Methods which simplifies work with javascript

Sujana Pathuri
3 min readOct 15, 2020

Most of the methods that can work on arrays, strings, and objects used to simplify our coding works, mostly loops. A few of those for quick reference with examples.

Data using for working examples of methods

.filter

It filters given data(array/object) based on given condition and returns data in an array format. It return all values which match with the passed condition.

here employee means empNames array

.some

It will useful to look some condition exists in object/array. It returns true if condition satisfy else false.

.every

It will useful to check every item in object/array is met with defined condition or not. It returns true if condition satisfy else false.

.find

It finds given data(array/object) based on given condition and returns data in an object format. It returns only the first value match with the passed condition.

.sort

Used to sort elements in an array or object. Custom sorting functionality gives flexibilty to sorting.

Set

Set can store any types of values whether primitive or objects, it only store unique values of any type.

We have so many functionalities with Set, To know more about the set object, go through

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

.substring

It is used to extract sub string form main string based on index values

.splice

It is used to replace or remove elements in an array by giving index position and mentioning a number for how many wants to remove.

.slice

It returns selected elements as a new array object, here we need to give start and end index positions to select elements. Original array not change like splice.

.split

It split a string into array of substrings, and returns a new array.

We have many predefined ways to make work simple and efficient, but how complex and different can use those ways is upto us. Keep on try new way of using based on scenario to take ready-in advantage to required extent.

--

--

Sujana Pathuri

Digging deep with calm mind. Journey with self. Finding stagnated vision.