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 :: get dir from filepath javascript 
Javascript :: firestore batch add array 
Javascript :: chartjs Uncaught ReferenceError: Utils is not defined 
Javascript :: reactbootstrap multiselect 
Javascript :: useref 
Javascript :: change theme in react-toastify 
Javascript :: iso to date javascript 
Javascript :: javascript format number 2 digits 
Javascript :: add props to jsx element 
Javascript :: javascript make async get request 
Javascript :: how to get the timestamp in javascript 
Javascript :: isInt js 
Javascript :: multiple click events in react 
Javascript :: javascript includes 
Javascript :: stomp.min.js cdn 
Javascript :: open xcode shorthand react native 
Javascript :: js number format 
Javascript :: javascript remove style 
Javascript :: discord.js clean content 
Javascript :: how to sort an array of objects by two fields in javascript 
Javascript :: nodejs javascript heap out of memory 
Javascript :: regex exact match case insensitive 
Javascript :: importing json file in javascript 
Javascript :: show hide element jquery 
Javascript :: append child at the top 
Javascript :: js convert array of arrays to array 
Javascript :: javascript element edit text 
Javascript :: react index.jsx example 
Javascript :: pass props in link next js 
Javascript :: flatten an array without using .flat(); 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =