javascript2 (1)
javascript2 (1)
String toUpperCase()
String toLowerCase()
String concat()
let t1 = "Hello";
let text2 = "students";
let text3 = text1.concat(" ", text2);
String trim()
let str = ' jayajasmine ';
let newStr = str.trim();
console.log(newStr);
String trimStart()
let str = " jasminel";
console.log(str);
String repeat()
String replace()
let str = 'js is a compiled language';
JavaScript Arrays
const cars = ["rcm", "college", "management"];
console.log(cars);
const cars = ["rcm", "college", "management"];
let car = cars[0];
console.log(car);
cars.length // Returns the number of elements
cars.sort() // Sorts the array
Looping Array Elements
.forEach()
const data = [];
data[0] = "ramesh";
person[1] = "nayak";
person[2] = 24;
data.length();
data[0];
const data = [];
data[“firstname”] = "ramesh";
person[“lastname”] = "nayak";
person[“age”] = 24;
data.length();
data[0];
toString()
const cars = ["rcm", "college", "management"];
let data=cars.toString();
console.log(cars);
The join() method is used to add all the array elements in string
let family= ["father", "mother", "sister",”brother"];
let join= fruits.join(" * ");
Console.Log(join);
The pop() method removes the last element from an array
let family= ["father", "mother", "sister",”brother"];
let man= fruits.pop();
Console.Log(man);
push() method is used to add new element in the end
let family= ["father", "mother", "sister",”brother"];
let data= fruits.push();
Console.Log(data);
The shift() method removes the first array element and "shifts" all other elements to a lower index
let family= ["father", "mother", "sister",”brother"];
let data= fruits.shift();
Console.Log(data);
The unshift() method adds new elements to the beginning of an array
let family= ["father", "mother", "sister",”brother"];
let data= fruits.unshift();
Console.Log(data);
Deleting elements leaves undefined holes in an array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
delete fruits[0];
concat() method is used to connecting the two array
let family= ["father", "mother", "sister",”brother"];
let friend= ["bestfriend", "closefriend",];
let fafr=family.concat(friend);
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 0, "Lemon", "Kiwi");
the 1st parameter defines the position where new elements should be added
the 2nd parameter defines the how many elemnets should be removed
Slice out a part of an array starting from array element
const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
const citrus = fruits.slice(1, 3);
the 1st parameter defines the start argument
the 2nd parameter but not include this argument
const fruits = ["Apple", "Orange", "Apple", "Mango"];
let position = fruits.indexOf("Apple") + 1;
indexOf() method searches an array for an element value and returns its position.
Include()
This method is used to check the element is present in the array or not
Sort()
This method is used to sort element alphabetically
Declaring a constant array does NOT make the elements unchangeable
const name= ["Sahoo", "jasmine", "jaya"];
name[0] = "donu";
cars.push("sahoo");
reverse()
reverse method is used to reverse the array element