Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

typescript interface with unknown keys

//credit goes to Andrés Reales
interface AllPropertiesString {
  [key: number]: string;
  [key: string]: string;
}

const random: AllPropertiesString = <AllPropertiesString>{};
random[1] = 'This is the value for number 1';
random['1'] = 'This is a string';

console.log(random[1]); // will display 'This is a string'
console.log(random["1"]); // will display 'This is a string'
Comment

PREVIOUS NEXT
Code Example
Javascript :: getting empty req.body 
Javascript :: javascript concat two arrays 
Javascript :: date javascript format 
Javascript :: includes method javascript 
Javascript :: js get all dublicates indexes in array 
Javascript :: sequelize operators 
Javascript :: else if javascript 
Javascript :: how to chunk a base 64 in javascript 
Javascript :: js associative array push 
Javascript :: how to convert seconds in hours minutes and seconds js 
Javascript :: cookie in javascript 
Javascript :: ReactDOMServer import 
Javascript :: how to get variable value outside function in javascript 
Javascript :: A simple static file server built with Node.js 
Javascript :: jquery id value input 
Javascript :: sentry ignore errors 
Javascript :: javascript current target 
Javascript :: useref material ui 
Javascript :: how check if a form date is before today javascript 
Javascript :: change the position of div using javascript 
Javascript :: web3 js get network 
Javascript :: if variable is string javascript 
Javascript :: use svg image in next js 
Javascript :: js day monday tuesday wednesday 
Javascript :: TypeError: Class constructor Model cannot be invoked without 
Javascript :: javascript random int 
Javascript :: vue custom events 
Javascript :: webpack file-loader 
Javascript :: js addeventlistener foreach 
Javascript :: javascript redirection 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =