Extract only values from JSON object in javascript without using a loop

前端 未结 4 969
暖寄归人
暖寄归人 2021-01-14 03:01

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

4条回答
  •  孤街浪徒
    2021-01-14 03:12

    With ES2017 you have Object.values(). You can polyfill it also.

    Only you need is transform JSON to JavaScript object and call Object.values(). The result is an array of values.

    var obj = JSON.parse(jsonData);
    var result = Object.values(obj);
    

提交回复
热议问题