What do you want to save?
Add Code snippet
New code examples
-
Javascript 2022-02-02 17:41:22
clone an object javascript
var student = {name: "Rahul", age: "16", hobby: "football"}; //using ES6 var studentCopy1 = Object.assign({}, student); //using spread syntax var studentCopy2 = {...student}; //Fast cloning with data loss var studentCopy3 =... Add solution -
Javascript 2022-02-02 08:11:11
javascript foreach key value
myObject ={a:1,b:2,c:3} //es6 Object.entries(myObject).forEach(([key, value]) => { console.log(key , value); // key ,value }); //es7 Object.keys(myObject).forEach(key => { console.log(key , myObject[key]) // key , value }) Add solution -
Javascript 2022-01-29 07:30:50
javascript push object into array with variable key
//Normal Javascript var key = "happyCount"; var obj = {}; obj[key] = someValueArray; myArray.push(obj); //OR //If you're able to use ES6 and Babel, you can use this new feature: { [yourKeyVariable]: someValueArray, } Add solution -
Javascript 2022-01-22 02:10:28
js new array of length
ES6 gives us Array.from so now you can also use Array.from(Array(5)).forEach(alert) If you want to initialize with a certain value, these are good to knows... Array.from('abcde'), Array.from('x'.repeat(5)) or Array.from({length: 5}, (v, i) => i) /... Add solution