0

For example, I have an array = []. I want to restrict the array length. How should I initialize it? Is there anything for restricting the size?in Javascript i cant make it? i have a JSON data with 250 length,i want them to restrict to first 20 values?

1 Answers1

0

Define array size. Example:

var arr = new Array(5);
MH2K9
  • 11,951
  • 7
  • 32
  • 49
  • 1
    This does not restrict the size of the array, it only initilalizes it on construction. You can still do arr.push(...) – jo_va Mar 18 '19 at 11:48