a_sid
0
Q:

get length of array


 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.length; 
22
var numbers = [1, 2, 3, 4, 5];
var length = numbers.length;
for (var i = 0; i < length; i++) {
  numbers[i] *= 2;
}
// numbers is now [2, 4, 6, 8, 10]
18
var arr = [10,20,30,40,50]; //An Array is defined with 5 instances

var len= arr.length;  //Now arr.length returns 5.Basically, len=5.
console.log(len); //gives 5
console.log(arr.length); //also gives 5
16
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.length;   // length is a property, not function !
9
var colors = ["Red", "Orange", "Blue", "Green"];
var colorsLength=colors.length;//4 is colors array length 

var str = "bug";
var strLength=str.length;//3 is the number of characters in bug
20
// In Javascript
var x = [1,2,3];
console.log(x.length);
2
// array::size
#include <iostream>
#include <array>

int main ()
{
  std::array<int,5> myints;
  std::cout << "size of myints: " << myints.size() << std::endl;
  std::cout << "sizeof(myints): " << sizeof(myints) << std::endl;

  return 0;
}
3
  var x = [];
  console.log(x.size());
  console.log(x.length);
  console.log(x.size()==x.length);
  x =[1,2,3];
  console.log(x.size());
  console.log(x.length);
  console.log(x.size()==x.length);
//arjun
-1

New to Communities?

Join the community