1. The $.map method that comes with jQuery
$.map(json, function (n) { return n; });
This method was originally used to copy an array. Today I use it to copy a certain item in the array. Record, found that the field name was missing, and later discovered the second method.
2. Deep copy and shallow copy
// Shallow copy (only copy top-level non-object elements)
var newObject = jQuery.extend({}, oldObject);
// Deep copy (copy layer by layer until Bottom layer)
var newObject = jQuery.extend(true, {}, oldObject);
uses the deep copy method, and the phenomenon of missing fields when copying objects is no longer found.
3. Array filtering I looked for the JavaScript array method, but there is no filtering method. Later I found that jQuery provides it. I tried it and it worked very well.
$.grep(jsonTmp, function (item)
{
return item.LegendTitle == field;
}, false);
Just write the content of the function according to the actual needs. If not, refer to the help of jQuery, there Very detailed.
4. By the way, the sorting of the array
json2.sort(function (a, b) { return a["requiredColumn"]["crimeTime"] > b["requiredColumn"]["crimeTime"] ? 1 : -1 });
This is also more convenient to use
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn