如何在jquery中向数组添加值?

时间:2016-08-24 04:53:18

标签: javascript jquery arrays

我有以下数组,我将值附加到字符串strOrderArr。

  var strOrderArr = '';
            $.each(uploadData, function (i, item) {
                strOrderArr = strOrderArr + "{";
                strOrderArr = strOrderArr + "'upld_contentlabel':" + "'" + item.label + "'" + ",";
                strOrderArr = strOrderArr + "'upld_DocumentName':" + "'" + item.DocName + "'" + ",";
                strOrderArr = strOrderArr + "'upld_docid':" + "'" + item.DocId + "'" + ",";
                strOrderArr = strOrderArr + "'upld_contentvalue':" + "'" + item.value + "'";
                strOrderArr = strOrderArr + "'upld_contentid':" + "'" + item.doc_contentid + "'";
                //strOrderArr = strOrderArr + "'TotalCost':" + "'" + $(item).find("#lblTotalAmt_" + row).text() + "'";
                strOrderArr = strOrderArr + "},";

            });

我想从其他数组

向strOrderArr追加一个值
  $.each(Content, function (key, value) {
 strOrderArr=strOrderArr+value.doc_contentid;

});

这可能吗?我尝试了如上所述,但值不附加。那我哪里错了?提前谢谢。

1 个答案:

答案 0 :(得分:1)

var object1 = {
  apple: 0,
  banana: { weight: 52, price: 100 },
  cherry: 97
};
 
// Assuming JSON.stringify - not available in IE<8
$( "#log" ).append( JSON.stringify( object1 ) );
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<div id="log"></div>