Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to convert an object to a list in js

/*
if you want to create an array from all the properties names of an object you use
the Object.keys() method;
if you want to make an array out of the values you use the Object.values() method;
if you want to create an array from both keys and values use the
Object.entries() method;
*/

const client= {
  "name": "John",
  "id": 00019857,
  "itemsPurchased": [
  	"apple",
  	"banana",
  	"kiwi",
  ]
}

Examples:
// with the keys
console.log(Object.keys(client));
// output: ["name", "id", "itemsPurchased"]

// with the values
console.log(Object.values(client));
// output: ["John", 00019857, ["apple", "banana", "kiwi"]]

// with both keys and values
console.log(Object.entries(client));
// output: [("name", "john"), ("id", 00019857), ("itemsPurchased", ["apple", "banana"])]
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript array any 
Javascript :: data down action up 
Javascript :: check array values equal js 
Javascript :: how to add d3.js in angular 
Javascript :: express send code 
Javascript :: how to emty an array in javascript 
Javascript :: useref reactjs 
Javascript :: stopping setinterval 
Javascript :: to do list local storage javascript 
Javascript :: round innerhtml up 
Javascript :: discord.js embed timestamp 
Javascript :: Conditionallu inline styling in react 
Javascript :: use svg image in next js 
Javascript :: jquery download 
Javascript :: filter through date in mongooes 
Javascript :: min and max javascript 
Javascript :: generators in javascript 
Javascript :: update photoURL firebase 
Javascript :: installing react router dom 
Javascript :: nodejs express server img src 
Javascript :: Lodash.chunk chunk 
Javascript :: js sort 
Javascript :: vuejs router params 
Javascript :: jquery datatable passing of parameters 
Javascript :: how to export mongodb database to json 
Javascript :: what is template engine in express 
Javascript :: innertext data form js 
Javascript :: node map has value 
Javascript :: mongoose search in multiple fields 
Javascript :: bootstrap open tab from link data-toggle="tab" 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =