仅从JavaScript对象获取文本

时间:2019-01-19 13:42:16

标签: javascript arrays json

我只想获取下面对象中的键的值

const params = [{"title":"How to code","author":"samuel","category":"categoery","body":"this is the body"}]

我很难做到这样

3 个答案:

答案 0 :(得分:0)

Object.values(params)

这将存储params对象的值数组

答案 1 :(得分:0)

这是一个列出对象值的示例,在这种情况下使用foreach导致您在数组中使用对象?希望对您有帮助

var params = [{"title":"How to code","author":"samuel","category":"categoery","body":"this is the body"}];
params.forEach(element=> {
        var _onjkey=Object.keys(element);
        _onjkey.forEach(key=>{
                console.log(element[key]);
        })
});

答案 2 :(得分:0)

您可以通过Object.values()获取对象键的值。

const params = [{"title":"How to code","author":"samuel","category":"categoery","body":"this is the body"}]
params.map(data => {
  console.log(Object.values(data))
})