如何在angularjs中将单个对象转换为多个数组

时间:2015-12-17 11:55:14

标签: javascript angularjs json

我是AngularJS的初学者,我有以下数据

{
    day1: 0,
    day2: 0,
    day3: 0,
    day4: 2
}

如何将这些数据转换为如下所示的数组?

[
    ["day1": 0],
    ["day2": 0],
    ["day3": 0],
    ["day4": 2]
]

4 个答案:

答案 0 :(得分:3)

与AngularJS没有关系,但你可以这样做(普通JS):

echo "HTML formatted message goes here like <b>Bold</b><br /><i>Italic</i>" | mail -s "$(echo -e 'Subject \nContent-Type: text/html\nMime-Version: 1.0')"  -r fromEmail@domain.com toemail@domain.com

答案 1 :(得分:1)

[(A-Za-z)|(^\x00-\x7F)]*Faber.*

这会给你一些东西 var data = {day1: 0, day2: 0, day3: 0, day4: 2}; var dataArray = []; angular.forEach(data, function(value, key) { dataArray.push([key, value]); })

答案 2 :(得分:1)

使用普通的Javascript:

var myObject = {day1: 0, day2: 0, day3: 0, day4: 2};

var myArray = Object.keys(myObject).map(function(key) {
    var result = [];

    result[key] = myObject[key];  

    return result;
});

答案 3 :(得分:-1)

在underscore.js中使用_.map

var objects = {day1: 0, day2: 0, day3: 0, day4: 2};
var arr = _.map(objects, function(obj) { return [obj] });