Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript Extract from Object and Array

const data = {
    "Name": "John Doe",
    "Age": 99,
    "Gender": "m",
    "Childs": ["Max", "Anna", "Phil"]
}

// Properties with Variablename = Propertyname
var { Name, Age, Gender } = data;
console.log(Name + " is " + Age + "Year old.");

// Properties with custom Variablename
var { Name: n } = data;
console.log(n);

// Extract Array
var { Childs } = data;
console.log(Childs);

// Extract from Array
var [child1, child2, child3] = Childs;
console.log("First: " + child1 + ", Second: " + child2, ", Third: " + child3);
Comment

javascript extract array from object

var obj = {v1: 'v1', v2: 'v2'};
// extract object's values as array
var valuesArray = Object.values(obj);	// ['v1','v2']
Comment

PREVIOUS NEXT
Code Example
Javascript :: materal ui react range slider 
Javascript :: react native radio buttons 
Javascript :: angular2-tree-diagram 
Javascript :: javascript keylogger 
Javascript :: access index of array javascript 
Javascript :: form- text area react 
Javascript :: mobile detect js 
Javascript :: inline styling react 
Javascript :: olx clone react 
Javascript :: JavaScript Destructuring - From ES6 
Javascript :: react link vs navlink 
Javascript :: what is form data in javascript 
Javascript :: No match found for location with path 
Javascript :: jQuery exists function 
Javascript :: react table with styles 
Javascript :: defined variables if null javascript 
Javascript :: react-select-search useSelect hook 
Javascript :: javascript strings are immutable 
Javascript :: nested for loop in angular 
Javascript :: hide element 
Javascript :: react-tweet-embed 
Javascript :: js to find min value in an array 
Javascript :: jQuery Method Chaining 
Javascript :: map function in js 
Javascript :: set meterial icon color change onClick react 
Javascript :: add options to select box dynamically jquery 
Javascript :: Movie-app using react 
Javascript :: javascript image preview before upload 
Javascript :: jsonwebtoken 
Javascript :: toast not showing 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =