Some method in JavaScript

Raghib Ahsan
2 min readNov 2, 2020

JavaScript

JavaScript is a scripting or programming language that allows you to implement complex features on web pages. You can run it on Google Chrome, Internet Explorer, Safari, etc. JavaScript can execute not only in the browser but also on the server and any device which has a JavaScript Engine.

isArray( )

This method checks the passed value is an array or not.

Array.isArray([1, 2, 3]);  // true
Array.isArray({foo: 123}); // false

concat( )

This method is used to add two or more array.

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);
console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]

indexof( )

We can know the index number of an element in an array by using this method.

const beasts = ['ant', 'bison', 'camel', 'duck'];console.log(beasts.indexOf('bison'));
// expected output: 1

unshift( )

This method adds elements initial to the array and returns the new array.

const array1 = [1, 2, 3];console.log(array1.unshift(4, 5));
// expected output: 5
console.log(array1);
// expected output: Array [4, 5, 1, 2, 3]

charAt( )

Suppose we store a number in a variable. When we use this method in a string then we can know the exact character whose position is which we store a number.

const sentence = 'The quick brown fox jumps over the lazy dog.'
const index = 4;
console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// expected output: "The character at index 4 is q"

slice( )

This method divides the string and returns a new string.

const str = 'The quick brown fox jumps over the lazy dog.';console.log(str.slice(31));
// expected output: "the lazy dog."

trim( )

It removes the whitespace from both start and endpoints.

const greeting = '   Hello world!   ';
console.log(greeting.trim());
// expected output: "Hello world!";

repeat( )

The method constructs and returns a new string that contains the specified number.

const greeting = '   Hello world!   ';
const chorus = 'Because I\'m happy. ';
console.log(`Chorus lyrics for "Happy": ${chorus.repeat(3)}`);// expected output: "Chorus lyrics for "Happy": Because I'm happy. Because I'm happy. Because I'm happy."

parseInt( )

It is a function that converts a string to an integer.

parseInt('12'); // 12

toUpperCase( )

It returns all the value of the string to uppercase.

const sentence = 'dog.';console.log(sentence.toUpperCase());
// expected output: "DOG."

--

--