Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

destructure dynamic properties

let object = {x: 3, y: 6}
let propertyName = 'x'

// the value of the destructured property is assigned to a new variable
let {[propertyName]: value} = object

console.log(value) // 3
Comment

Destructuring objects by extracting properties of variables with dynamic values

const myTitle= 'title';

const myObject = {title: 'My Title', name: 'My Name'};
const {[myTitle]: myObjectTitle} = myObject;

console.log(myObjectTitle); // "My Title"
Comment

PREVIOUS NEXT
Code Example
Javascript :: nodejs check if express started 
Javascript :: speedtest-net node.js 
Javascript :: javascript get element by custom attribute 
Javascript :: disable eslint 
Javascript :: js array find string element with max length 
Javascript :: neo4j create relationship between existing nodes 
Javascript :: javascript round date to nearest 15 minutes 
Javascript :: rounding off numbers javascript 
Javascript :: How to create react app with yarn, npx or npm 
Javascript :: replace double slash with single slash node.js 
Javascript :: react form reload page 
Javascript :: javascript newline in alert box 
Javascript :: how to find out which version of react 
Javascript :: javascript parse a json string 
Javascript :: remove one array from another javascript 
Javascript :: async queue.push 
Javascript :: collection to array javascript 
Javascript :: object in array javascript 
Javascript :: get last item in array 
Javascript :: how get value of json encode in laravel 
Javascript :: mysql connection in node js 
Javascript :: Convert number to array of digits js 
Javascript :: how-to-save-array in Local storage - js 
Javascript :: Binary Agents 
Javascript :: jsconfig.json 
Javascript :: firebase cloud functions schedule function run time 
Javascript :: jquery remove child 1 elemtn 
Javascript :: clear input field jquery 
Javascript :: javascript compare arrays remove duplicates 
Javascript :: react disable eslint errors 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =