is there a \"Nice\" way to get all the values out of a json object (I don\'t care about the keys) - just get the values into array, without using a loop ? (lang is Javascr
It depends on how you define "loop".
You can extract the properties with Object.keys
and then map
them to their values.
… it's still essentially a loop under the hood though.
var json = `{ "foo": 1, "bar": 2, "baz": 3 }`;
var obj = JSON.parse(json);
var values = Object.keys(obj).map(function (key) { return obj[key]; });
console.log(values);
With weaker browser support you could use the values
method.
var json = `{ "foo": 1, "bar": 2, "baz": 3 }`;
var obj = JSON.parse(json);
var values = Object.values(obj);
console.log(values);