Asit kumar dey
4 min readNov 6, 2020

--

JavaScript string

  1. toUpperCase():

This method will let you convert uppercase letters to a capital letter. Like, “ Have a good day.” toUpperCase() the method will convert it to: “HAVE A GOOD DAY.” It converts all lower case letters in array to upper case. This function has a cousin called toLowercase(). This method can change uppercase letters to lowercase. Like, “have a good day.”

var wish = “I’ll buy you a car.”;console.log(wish.toUpperCase()) // I'LL BUY YOU A CAR.
console.log(wish.toLowercase()) // i'll buy you a car.

2. concat()

Theconcat() method connects two string arguments and provides another string. This function can be used to add two arrays.

var str1 = ['a', 'b', 'c'];var str2 = ['d', 'e', 'f'];console.log(str1.concat(str2));
// ['a', 'b', 'c', 'd', 'e', 'f']
console.log(str2.concat(str1));
// ['f', 'e', 'd', 'c', 'b', 'a']

3. lastIndexOf():

The lastIndexOf() method finds the index of the last occurrence of the specified text in a string. This method is also case-sensitive.

const foo = 'I hate dogs. so I stay away from dogs'const serchItem = 'dogs'console.log(foo.lastIndexOf(serchItem))
// The index of searchItem is 33

JavaScript number

4. parseInt():

The parseInt() method parses a string argument and converts it into an integer value. parseInt() returns the first number in the string. If the first is character cannot be converted then parseInt() will NaN.

var num1 = 20.2;
console.log(parseInt(num1));
// 20

5. parseFloat():

The parseFloat() function converts a string value to a floating-point number. It only returns the first number in the string. If the first is character cannot be converted then parseFloat() will NaN.

var f = parseFloat("60 years");
var g = parseFloat("He is 60 years old");
console.log(f)
// 60
console.log(g)
// NaN

6. isNaN():

The isNaN() method determines whether the passed value is a Number or not.

function feetToInch(x) {
if (isNaN(x)) {
return 'Not a Number!';
}
return x * 12;
}
console.log(feetToInch(2), 'inch')
// 24 inch

JavaScript Array:

7. foEach():

The forEach() method calls a function for each element in the array. It can take three parameters, currentValue, index, array. The currentValue parameter will return the current value of the element in the loop. The index parameter tells the index number of the element in the loop. And the array parameter returns the whole array.

var array1 = [30, 20, 10];array1.forEach(element => console.log(element));
// 30
// 20
// 10
array1.forEach((currentValue, index, array) => console.log(currentValue, index, array));
// 30 0 [ 30, 20, 10 ]
// 20 1 [ 30, 20, 10 ]
// 10 2 [ 30, 20, 10 ]

8. splice(): The splice() method removes items from an array and returns an array of rest items without removed items and if necessary inserts new elements in their place. Splice changes the original array. It takes two index values; the first is for a starting index and the second is for the number of elements to remove.

const nums = [1, 2, 32, 435, 4, 6, 456, 46];console.log(nums.splice(2, 5));
// [ 32, 435, 4, 6, 456 ]
console.log(nums); // Now splice changed the array.// changed array output: [1, 2, 46]

9. slice(): The slice() method returns a shallow copy of a segment of an array into a new array where the starting number represents the index of the item in that array and the ending number represents the previous element of the selected index in that array. The slice() method doesn’t change the original array.

const nums = [1, 2, 32, 435, 4, 6, 456, 46];console.log(nums.slice(2, 6));
// [ 32, 435, 4, 6 ]

10. reduce():

The reduce() method executes for a provided function for each element of the array and reduces that array to a single value. Here’s a simple explanation with an example:

const numbers = [1, 2, 32, 435, 4, 6, 456, 46];const total = nums .reduce((sum, num) =>(sum + num), 0)console.log(total);
// 982

Here the sum or reduced value of all the elements of the numbers array is 982.
The default value of the sum parameter is 0. The num parameter is adding one element to the sum parameter from left to right of the numbers array. Any value can be taken as the default value based on the elements of the array.

console.log(sum, num);// 1 0
// 2 1
// 32 3
// 435 35
// 4 470
// 6 474
// 456 480
// 46 936

The values of sum and num parameters are shown in the console above.

--

--

Asit kumar dey

Full stack web developer || Experienced with JavaScript , React js, ES6, Node js, Express, Mongo DB,