Javascript
JavaScript for Pythonistas Link to heading
dict.items()
Link to heading
for (const [key, value] of Object.entries(obj)) {
console.log(key, value);
}
getattr
Link to heading
const value = obj[key];
Transform a list of lists with key-values into a object Link to heading
const entries = [
['a', 1],
['b', 2],
];
const obj = Object.fromEntries(entries);
console.log(obj);
// Output: { a: 1, b: 2 }
Use the value of a variable (instead of the variable name) as the key in an object Link to heading
const x = 'abc';
const obj = {
[x]: '<whatever>'
};
console.log(obj);
// Output: { abc: '<whatever>' }
TypeScript Link to heading
ReferenceError: ts is not defined at (…) Link to heading
import * as ts from 'typescript';