Maximum size of an Array in Javascript

前端 未结 7 1769
我在风中等你
我在风中等你 2020-11-22 10:46

Context: I\'m building a little site that reads an rss feed, and updates/checks the feed in the background. I have one array to store data to display, and another which stor

7条回答
  •  花落未央
    2020-11-22 11:14

    You could try something like this to test and trim the length:

    http://jsfiddle.net/orolo/wJDXL/

    var longArray = [1, 2, 3, 4, 5, 6, 7, 8];
    
    if (longArray.length >= 6) {
      longArray.length = 3;
    }
    
    alert(longArray); //1, 2, 3

提交回复
热议问题