How to get the length of an array in javascript in this type of situations?

i want the length of ann array without directly touching it. i mean can store it in any variable or array from there i can get but not directly.
but is it possible to store it some where else and knowing it length or can i store the all the array element somewhere.

As i understand your requirements, Try this

var Newarr = Oldarr.slice();
var lenghtofarr=Newarr.length;

1 Like

but as per my knowledge slice is to trim a required part of the string but i want a store all the array in a variable.

You are referring to the string method phani. Arrays have their own slice method which allows you to make a copy of the array. See the following link

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

var origArr = [1,2,3],
newArr = origArr.slice(); // makes a copy of origArr;

origArr[3] = 4; //add to origArr

console.log(origArr); // [1,2,3,4]
console.log(newArr); // [1,2,3]

1 Like

o… i got it.
thanks to you both guys.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.