JavaScript some amazing string & Array


String includes method determines whether one string may be found within another string That returns true or false as appropriate.

const sentence=’i am learning javascript’;


expected output: true

2.Sting indexOf-

It defines the position of string values and numbers .You can get position any value but it should be case sensitive.

const sentence=’i am learning javascript’


expected output:5

3.LastIndex of Method:

It generally starts with last index of an array .it is generally used when vales becomes double :

const array=[‘one’, ‘two’, ‘three’, ‘one’]


expected output:3

4. concat METHOD

The concat() method is used to join two or more strings. It does not make changed the exiting strings and returns new string

var str1 = “Hello “;

var str2 = “Rashed!”;

var result = str1.concat(str2);


expected output: Hello Rashed!

5. toLowercase method:

The toLowerCase() method returns the string value that converted to lower case.You can convert to any capital letter to small letter.

// const str = ‘rasehd chy’;

// console.log(str.toUpperCase());

expected output: RASHED CHY

6. Array Map Method:

Map is a collection of keyed data items, just like an Object.It holds key-value pairs and remembers the original insertion order of the keys

const numbrs=[2,4,3,5,6]



expected output: [ 4, 8, 6, 10, 12 ]

7.Javascript Find Array Method :

The find() method executes the function once for each element present in the array:If it finds an array element where the function returns a true value, find() returns the value of that array element (and does not check the remaining values)

Otherwise it returns undefined

const numbrs=[8,4,5,9,6]

const result=numbrs.find(number>6)


expected output: [ 4, 8, 6, 10, 12 ]

8. Javascript Array Filter method:

The filter() Array method creates a new array with elements that fall under a given criteria from an existing array:

var numbers = [1, 3, 6, 8, 11];

var lucky = numbers.filter(function(number) {

return number > 7;



expected output: [8, 11]

Array Reduce Method:

It makes the array to a single value. reduce() does not execute the function for array elements without this method, original

Array remains the same.

var numbers = [1, 3, 6, 8, 11];

const sum=numbers.reduce((preValue,currentValue)=>{

return preValue+currentValue;



expected output: 29;

9.Array Reverse Method: it of the elements in an array. Thats means, the first array element becomes the last, and the last array element becomes the first.

const names=[‘rashed’,’minto’,’wahid’,’jamal’]

const result=names.reverse()


expected output: [ ‘jamal’, ‘wahid’, ‘minto’, ‘rashed’ ]

10.Javascript For each method :

The forEach() method calls a function once for each element in an array, in order. The function is not executed for array elements without values.

const numbers=[4,5,3,9,8,4,7]

const square=[]





expected output: [

16, 25, 9, 81,

64, 16, 49