How do I cancel JSON in JavaScript?

[
   {"task":"test","created":"/Date(1291676980607)/"},
   {"task":"One More Big Test","created":"/Date(1291677246057)/"},
   {"task":"New Task","created":"/Date(1291747764564)/"}
]

I looked here, and someone had the same question, but the “verified” correct answer was that in IE it would be different if the element was deleted and everything would be fine. My problem is that these elements are stored above, but when I go and grab them, repeat and return, the elements change to the opposite, and created- to the index 0, and task- to 1. Also, I need to return this as JSON.

Here is my main JS (value == int int which the user passes):

outputJSON = {};
for(x in json[value]){
    outputJSON[x] = _objectRevival(json[value][x]);
}
return outputJSON;

This returns:

created: Mon Dec 06 2010 15:09:40 GMT-0800 (Pacific Standard Time)
task: "test"
+3
source share
4 answers

undefined. . , :

var values = [
   [["task", "test"],              ["created", "/Date(1291676980607)/"]],
   [["task", "One More Big Test"], ["created", "/Date(1291677246057)/"]],
   [["task", "New Task"],          ["created", "/Date(1291747764564)/"]]
];

:

for (var i = 0; i < values.length; i++) {
    for (var k = 0; k < values[i]; k++) {
        // values[i][k][0] contains the label (index 0)
        // values[i][k][1] contains the value (index 1)
    }
}
+4

, javascript . (, - json [0], json [1], json [2]).

"" "", .

json[value]["task"]

json[value]["created"]

Update: . json-:

var before = [
   {"task":"test","created":"/Date(1291676980607)/"},
   {"task":"One More Big Test","created":"/Date(1291677246057)/"},
   {"task":"New Task","created":"/Date(1291747764564)/"}
];
var order = [];
for (var name in before[0]) {
   order.push(name); // puts "task", then "created" into order (for this example)
}

json . , :

var outputJSON = {};
for (var x in order) {
   if (order.hasOwnProperty(x)) {
      outputJSON[order[x]] = _objectRevival(json[value][order[x]]); // I'm not sure what _objectRevival is...do you need it?
   }
}
return outputJSON;
0

To ensure that a specific order is fulfilled for your output, simply replace json[value]in the loop with the forarray of properties of the object in the order that you want to display, in your case ["task", "created"].

0
source
var items = ["bag", "book", "pen", "car"];
items.reverse();

This will lead to the following conclusion:

car , pen, book, bag

Even if you have a JSON array, it will be the opposite.

0
source

Source: https://habr.com/ru/post/1779049/


All Articles