DEV Community

Dinesh G
Dinesh G

Posted on

My Java Full Stack Journey Learning in JavaScript

Day eleven in javascript .I shared the topics,what I learn today.

Array

.An array is a special variable that can hold multiple values in a single place.
.Instead of creating many variables, you can store them in one array.

eg:
let student1 = "John";
let student2 = "Mary";
let student3 = "Alex";

Better way:
let students = ["John", "Mary", "Alex"];

syntax:

let arrayName = [item1, item2, item3, ...];
Enter fullscreen mode Exit fullscreen mode

eg:

let fruits = ["Apple", "Banana", "Mango"];
Enter fullscreen mode Exit fullscreen mode

Accessing Array Elements
Arrays are zero-indexed → first item is at index 0.

let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana
console.log(fruits[2]); // Mango
Enter fullscreen mode Exit fullscreen mode

Types of array method():

push() → add to end
pop() → remove from end
unshift() → add to start
shift() → remove from start
splice() → add/remove at any position
slice() → copy part of array
indexOf() → find first index of value
lastIndexOf() → find last index of value
includes() → check if value exists
find() → return first matching element
findIndex() → return index of first match
forEach() → loop through array (no return)
map() → loop & return a new array
filter() → keep only elements that match condition
reduce() → reduce array to single value
reduceRight() → same as reduce, but from right side
every() → check if all elements match condition
some() → check if at least one element matches
sort() → sort array
reverse() → reverse array
Enter fullscreen mode Exit fullscreen mode

Happy coding...

Top comments (0)