DEV Community

PUSHAN VERMA
PUSHAN VERMA

Posted on

2 1

Arrays and Objects

Arrays
let marks =[10,20,30,40,50,90];
const fruits =["orange","apple","banana","grapes"];

const mixed =[3,5,[6,"pushan"]];
const arr4 =new Array(23,144,"verma"); //new method to initialize array , just like java

console.log(arr4);
console.log(marks);

Image description

length of array

console.log(marks.length);
Image description

//changing value of array
marks[1]=200000;
console.log(marks);
Image description

indexof
console.log(marks.indexOf(30)); // present so gives index of array
console.log(marks.indexOf(1000000000000)); // not present in array so gives -1
Image description

Methods in Arrays

push -add to last
marks.push(70);
console.log(marks);

unshift -add to first
marks.unshift(100);
console.log(marks);

pop - removes element from last of array
marks.pop();
console.log(marks);

shift-it will remove elements from begin
marks.shift();
console.log(marks);

splice - it removes the elements from given indexes
marks.splice(1,3);
console.log(marks);

*reverse - it reverse the array *
marks.reverse();
console.log(marks);

concat-concat the array with another array
marks2=[100,200,300,400,500];
marks=marks.concat(marks2);
console.log(marks);

Image description

  **All the properties are changing the whole array** 
Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay