Boost your Javascript knowledge

Some String Methods:

indexOf():

This method is used for getting the index number of any string.

We know that the index number starts from 0. the last index number will be total length — 1. example:

let sentence = “boost your js knowledge”;
let indexNumber = sentence.indexOf(“your”);

the result will be : 6

It means the index number started from 0 and from index number 6 the word ‘your’ is started.

lastIndexOf():

This method is used for getting the last index number of a repeated word.

let sentence = “boost your js knowledge and boost your self”;
let indexNumber = sentence.lastIndexOf(“boost”);

the result will be : 29

slice( start, end ):

This method is used for slicing a string. This is like slicing a cake with a knife.

It takes two parameters both indicate the index numbers. the starting position, and the ending position. example :

let fruits = “Apple, Banana, Mango”;
let result = fruits.slice(7, 13);

the result will be: Banana

the word Banana is a slice of index no 7 and 13.

substr( start, length):

This method is similar to the slice function but here the second parameter represents the length.

let fruits = “Apple, Banana, Mango”;

let result = fruits.substr(7, 6); — — Banana

let result = fruits.substr(7); — — Banana, Mango

concat():

This method is used for joining two or more strings.

let text = “Hello” + “ “ + “World!”;
let result= “Hello”.concat(“ “, “World!”);

Some Array Methods:

pop():

This method is used for removing the last element from an array.

It returns the removed element.

let fruits = [“Apple”, “Banana”, “Mango”];

fruits.pop() — — Mango

push():

This method is used for added an element in the last position in an array.

It returns the total number of elements after pushing.

let fruits = [“Apple”, “Banana”, “Mango”];

fruits.push(“pineapple”) — — 4

shift():

This method is used for removing the first element from an array.

It returns the removed element

let fruits = [“Apple”, “Banana”, “Mango”];

fruits.shift() — — Apple

unshift():

This method is used for adding an element in an array in the first position.

It returns the total number of elements after adding an element.

let fruits = [“Apple”, “Banana”, “Mango”];

fruits.unshift(“pineapple”) — — 4

sort():

This method is used for sorting array elements in ascending order like a dictionary. It returns the sorted array.

let alphabet = [ ‘b’, ‘a’, ‘d’, ‘c’]

alphabet.sort() — — [ ‘a’, ‘b’, ‘c’, ‘d’]

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Five Angular Admin Templates for Your Next Web Development Project

Counter App to Learn Redux With Hooks

Introduction to Svelte (Part 3 of 3)

DRYing up JS with Function Currying

ReactNative: Basic App skeleton (For Beginner)

How to build a dashboard with Bootstrap 4 from scratch (Part 1)

Deleting Database Entries From Firestore

Perks of creating an app using React Native

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Md Abdullah All Naim

Md Abdullah All Naim

More from Medium

My Journey: How I started Full-Stack Web Development.

A laptop, phone and glass of water sitting on a wooden desk.

Learning to Code Together

The War on Code

Starting Out with JavaScript