从反应类型脚本中的对象数组中获取所有值

时间:2018-12-14 06:40:46

标签: reactjs typescript

假设我有以下数据

const data = [{"No":100,"Name":"john","assigned":"James","status":"available"},{"No":200,"Name":"Abhi","assigned":"James","status":"blocked"}]

获得以下输出的最佳方法是什么?

const data = [["100", "john", "James", "available"],["200", "Abhi", "James", "blocked"]];

我尝试使用lodash。

_.values(data)

但是我得到的输出是

[object Object],[object Object].

2 个答案:

答案 0 :(得分:2)

使用纯js

const data = [{"No":100,"Name":"john","assigned":"James","status":"available"},{"No":200,"Name":"Abhi","assigned":"James","status":"blocked"}];

data1 = data.map( function(v) {
   return Object.values( v );
});

console.log(data1);

使用破折号:

const data = [{"No":100,"Name":"john","assigned":"James","status":"available"},{"No":200,"Name":"Abhi","assigned":"James","status":"blocked"}];

data1 = _.map( data, function(v) {
   return _.values( v );
});

console.log(data1);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"></script>

答案 1 :(得分:0)

data
  .map(element => Object.values(element));