Skip to content
Advertisement

JS remove array variable names

I’m new in JS… can someone help me to change this:

arr = [{type:'fruit', name:'apple', color:'red'},{type:'fruit', name:'banana', color:'yellow'}]

to this:

arr = [['fruit', 'apple', 'red'],['fruit', 'banana', 'yellow']]

Advertisement

Answer

You can map your array using Object.values() as a callback:

arr = arr.map(Object.values);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement