<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: kalhong90s</title>
    <description>The latest articles on DEV Community by kalhong90s (@kalhong90s).</description>
    <link>https://dev.to/kalhong90s</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1002136%2Fb92966a6-bd0b-4df5-893b-d632a6cc40ac.jpg</url>
      <title>DEV Community: kalhong90s</title>
      <link>https://dev.to/kalhong90s</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kalhong90s"/>
    <language>en</language>
    <item>
      <title>20 JavaScript: Shorthand Techniques that will save your time</title>
      <dc:creator>kalhong90s</dc:creator>
      <pubDate>Thu, 05 Jan 2023 08:33:31 +0000</pubDate>
      <link>https://dev.to/kalhong90s/top-20-javascript-shorthand-techniques-that-will-save-your-time-1bck</link>
      <guid>https://dev.to/kalhong90s/top-20-javascript-shorthand-techniques-that-will-save-your-time-1bck</guid>
      <description>&lt;p&gt;The shorthand techniques of any programming language help you to write more clean and optimized code. Shorthand techniques improve readability of your code and you can achieve your goal with less coding. Let’s discuss some of the shorthand techniques of JavaScript one by one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Declaring variables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let x; let y = 20; 

//Shorthand 
let x, y = 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Assigning values to multiple variables&lt;/strong&gt;&lt;br&gt;
We can assign values to multiple variables in one line with array destructuring.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let a, b, c; 
a = 5; 
b = 8; 
c = 12;

//Shorthand 
let [a, b, c] = [5, 8, 12];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. The Ternary operator&lt;/strong&gt;&lt;br&gt;
We can save 5 lines of code here with ternary (conditional) operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let number = 26; 
let isEven; 
if(number % 2){
 isEven = true; 
}else{ 
 isEven = false; 
} 
//Shorthand 
let isEven = number % 2 ? true : false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Assigning default value&lt;/strong&gt;&lt;br&gt;
We can use &lt;code&gt;OR(||)&lt;/code&gt;short circuit evaluation to assign a default value to a variable in case the expected value found empty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let imagePath; 
let path = getImagePath(); 
if(path !== null &amp;amp;&amp;amp; path !== undefined &amp;amp;&amp;amp; path !== '') { 
  imagePath = path; 
} else { 
  imagePath = 'default.jpg'; 
} 

//Shorthand 
let imagePath = getImagePath() || 'default.jpg';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. AND(&amp;amp;&amp;amp;) Short circuit evaluation&lt;/strong&gt;&lt;br&gt;
If you are calling a function only if a variable is true, then using &lt;code&gt;AND(&amp;amp;&amp;amp;)&lt;/code&gt; short circuit you can do it in a single line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
if (isLoggedin) {
 goToHomepage(); 
} 

//Shorthand 
isLoggedin &amp;amp;&amp;amp; goToHomepage();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here in shorthand technique, if &lt;code&gt;isLoggedin&lt;/code&gt; returns true, then only &lt;code&gt;goToHomepage()&lt;/code&gt;will execute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Swap two variables&lt;/strong&gt;&lt;br&gt;
To swap two variables, we often use a third variable. We can swap two variables easily with array destructuring assignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x = 'Hello', y = 55; 

//Longhand 
const temp = x; 
x = y; 
y = temp; 

//Shorthand 
[x, y] = [y, x];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Arrow Function&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
function add(num1, num2) { 
   return num1 + num2; 
} 

//Shorthand 
const add = (num1, num2) =&amp;gt; num1 + num2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Template Literals&lt;/strong&gt;&lt;br&gt;
We normally use + operator to concatenate string values with variables. With ES6 template literals we can do it in a more simple way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
console.log('You got a missed call from ' + number + ' at ' + time); 

//Shorthand 
console.log(`You got a missed call from ${number} at ${time}`);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Destructuring Assignment Shorthand&lt;/strong&gt;&lt;br&gt;
If you are working with any popular web framework, there are high chances you will be using arrays or data in the form of object literals to pass information between components and APIs. Once the data object reaches a component, you’ll need to unpack it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
const observable = require('mobx/observable');
const action = require('mobx/action');
const runInAction = require('mobx/runInAction');

const store = this.props.store;
const form = this.props.form;
const loading = this.props.loading;
const errors = this.props.errors;
const entity = this.props.entity;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Shorthand
import { observable, action, runInAction } from 'mobx';

const { store, form, loading, errors, entity } = this.props;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can even assign your own variable names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { store, form, loading, errors, entity:contact } = this.props;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10. Multiple condition checking&lt;/strong&gt;&lt;br&gt;
For multiple value matching, we can put all values in array and use indexOf() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
if (value === 1 || value === 'one' || value === 2 || value === 'two') { 
// Execute some code 
} 

// Shorthand 
if ([1, 'one', 2, 'two'].indexOf(value) &amp;gt;= 0) { 
// Execute some code 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;11. Object Property Assignment&lt;/strong&gt;&lt;br&gt;
If the variable name and object key name is same then we can just mention variable name in object literals instead of both key and value. JavaScript will automatically set the key same as variable name and assign the value as variable value.&lt;/p&gt;

&lt;p&gt;let firstname = 'Amitav'; &lt;br&gt;
let lastname = 'Mishra';&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//Longhand 
let obj = {firstname: firstname, lastname: lastname}; 

//Shorthand 
let obj = {firstname, lastname};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;12. String into a Number&lt;/strong&gt;&lt;br&gt;
There are built in methods like parseInt and parseFloat available to convert a string to number. We can also do this by simply providing a unary operator (+) in front of string value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let total = parseInt('453'); 
let average = parseFloat('42.6'); 

//Shorthand 
let total = +'453'; 
let average = +'42.6';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;13. Repeat a string for multiple times&lt;/strong&gt;&lt;br&gt;
To repeat a string for a specified number of time you can use a for loop. But using the repeat() method we can do it in a single line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
let str = ''; 
for(let i = 0; i &amp;lt; 5; i ++) { 
  str += 'Hello '; 
} 
console.log(str); // Hello Hello Hello Hello Hello 

// Shorthand 
'Hello '.repeat(5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Tip: Want to apologize to someone by sending 100 times “sorry”? Try it with &lt;em&gt;repeat()&lt;/em&gt; method. If you want to repeat each string in a new line, then add &lt;em&gt;\n&lt;/em&gt; to the string.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'sorry\n'.repeat(100);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;14. Exponent Power&lt;/strong&gt;&lt;br&gt;
We can use Math.pow() method to find the power of a number. There is a shorter syntax to do it with double asterik (**).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
const power = Math.pow(4, 3); // 64 

// Shorthand 
const power = 4**3; // 64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;15. Double NOT bitwise operator (~~)&lt;/strong&gt;&lt;br&gt;
The double NOT bitwise operator is a substitute for Math.floor() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Longhand 
const floor = Math.floor(6.8); // 6 

// Shorthand 
const floor = ~~6.8; // 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;16. Find max and min number in array&lt;/strong&gt;&lt;br&gt;
We can use for loop to loop through each value of array and find the max or min value. We can also use the Array.reduce() method to find the max and min number in array.But using spread operator we can do it in a single line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Shorthand 
const arr = [2, 8, 15, 4]; 
Math.max(...arr); // 15 
Math.min(...arr); // 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;17. For loop&lt;/strong&gt;&lt;br&gt;
To loop through an array we normally use the traditional for loop. We can make use of the for...of loop to iterate through arrays. To access the index of each value we can use for...in loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = [10, 20, 30, 40]; 

//Longhand 
for (let i = 0; i &amp;lt; arr.length; i++) { 
  console.log(arr[i]); 
} 
//Shorthand 
//for of loop 
for (const val of arr) { 
  console.log(val); 
} 
//for in loop 
for (const index in arr) { 
  console.log(arr[index]); 
}
We can also loop through object properties using for...in loop.

let obj = {x: 20, y: 50}; 
for (const key in obj) { 
  console.log(obj[key]); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;18. Merging of arrays&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr1 = [20, 30]; 

//Longhand 
let arr2 = arr1.concat([60, 80]); 
// [20, 30, 60, 80] 

//Shorthand 
let arr2 = [...arr1, 60, 80]; 
// [20, 30, 60, 80]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;19. Deep cloning of multi-level object&lt;/strong&gt;&lt;br&gt;
To deep clone a multi-level object, we can iterate through each property and check if the current property contains an object. If yes, then do a recursive call to the same function by passing the current property value (i.e. the nested object).We can also do it by using JSON.stringify() and JSON.parse() in a single line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let obj = {x: 20, y: {z: 30}}; 

//Longhand 
const makeDeepClone = (obj) =&amp;gt; { 
  let newObject = {}; 
  Object.keys(obj).map(key =&amp;gt; { 
    if(typeof obj[key] === 'object'){ 
      newObject[key] = makeDeepClone(obj[key]); 
    } else { 
      newObject[key] = obj[key]; 
    } 
  }); 
 return newObject; 
} 
const cloneObj = makeDeepClone(obj); 

//Shorthand 
const cloneObj = JSON.parse(JSON.stringify(obj));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;20. Get character from string&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let str = 'jscurious.com'; 

//Longhand 
str.charAt(2); // c 

//Shorthand 
str[2]; // c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Thanks for reading!
&lt;/h2&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>20 JavaScript: Array Methods</title>
      <dc:creator>kalhong90s</dc:creator>
      <pubDate>Thu, 05 Jan 2023 04:24:08 +0000</pubDate>
      <link>https://dev.to/kalhong90s/20-javascript-array-methods-276j</link>
      <guid>https://dev.to/kalhong90s/20-javascript-array-methods-276j</guid>
      <description>&lt;p&gt;In this tutorial, you will learn JavaScript Array Methods including examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript Array Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The following array methods in javascript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Array pop() Method&lt;/li&gt;
&lt;li&gt;Array push() Method&lt;/li&gt;
&lt;li&gt;Array toString() Method&lt;/li&gt;
&lt;li&gt;Array join() Method&lt;/li&gt;
&lt;li&gt;Array splice() Method&lt;/li&gt;
&lt;li&gt;Array sort() Method&lt;/li&gt;
&lt;li&gt;Array shift() Method&lt;/li&gt;
&lt;li&gt;Array unshift() Method&lt;/li&gt;
&lt;li&gt;Array reverse() Method&lt;/li&gt;
&lt;li&gt;Array concat() Method&lt;/li&gt;
&lt;li&gt;Array slice() Method&lt;/li&gt;
&lt;li&gt;Array filter() Method&lt;/li&gt;
&lt;li&gt;Array find() Method&lt;/li&gt;
&lt;li&gt;Array forEach() Method&lt;/li&gt;
&lt;li&gt;Array map() Method&lt;/li&gt;
&lt;li&gt;Array reduce() Method&lt;/li&gt;
&lt;li&gt;Array some() Method&lt;/li&gt;
&lt;li&gt;Array every() Method&lt;/li&gt;
&lt;li&gt;FindIndex() Array Method&lt;/li&gt;
&lt;li&gt;Array Include() Method&lt;/li&gt;
&lt;li&gt;IndexOf() Array Method&lt;/li&gt;
&lt;li&gt;Array lastIndexOf() Method&lt;/li&gt;
&lt;li&gt;JavaScript Array isArray() Method&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1: Array pop() Method&lt;/strong&gt;&lt;br&gt;
The javascript pop() method is used to remove the last element from an array.&lt;/p&gt;

&lt;p&gt;The method returns the value of the removed item.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.pop(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
// New array:  PHP, Python, Java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2: Array push() Method&lt;/strong&gt;&lt;br&gt;
The js push() method is used to add a new element to the end from an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.push("JavaScript");  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
// New array:  PHP, Python, Java, C, JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3: Array toString() Method&lt;/strong&gt;&lt;br&gt;
The js toString() method is used to convert array to string.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.toString();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;// output&lt;br&gt;
PHP, Python, Java, C&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4: Array join() Method&lt;/strong&gt;&lt;br&gt;
The javascript join() method is used to join the elements of an array into a string.&lt;/p&gt;

&lt;p&gt;In otherwords, The "join()" method puts all the elements of the array into a string list. This method difference from "toString()" method.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.join(" - ");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// output
PHP - Python - Java - C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5: Array splice() Method&lt;/strong&gt;&lt;br&gt;
The javascript splice() method is used to add and remove items from an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;syntax
================
array.splice(index, howMany, [element1][, …, elementN]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;index − Index param specifies where a new item should be inserted.&lt;/li&gt;
&lt;li&gt;howMany − An integer indicating the number of old array elements to remove.&lt;/li&gt;
&lt;li&gt;If howMany set to 0, no items will be removed in array list.
Ex:-
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.splice(2, 0, "Javascript", "Rust"); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Output
new array: PHP, Python, Javascript, Rust, Java, C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6: Array sort() Method&lt;/strong&gt;&lt;br&gt;
The javascript array sort() method either alphabetic or numeric sorts an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];
 lang.sort();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Outuput
array: C, Java, PHP, Python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7: Array shift() Method&lt;/strong&gt;&lt;br&gt;
The javascript shift() method is used to remove the first element from an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"]; 
 lang.shift(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Output
new array: Python, Java, C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8: Array unshift() Method&lt;/strong&gt;&lt;br&gt;
The js unshift() method adds a new element to the beginning of an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"]; 
 cars.unshift("JavaScript");   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Output 
New array: JavaScript, PHP, Python, Java, C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9: Array reverse() Method&lt;/strong&gt;&lt;br&gt;
The method is used for reverses the order of the elements in an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];             
 lang.reverse();   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Outuput
array: C, Java, PHP, Python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;10: Array concat() Method&lt;/strong&gt;&lt;br&gt;
The javascript concat() method joins two or more arrays and makes a new one.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C"];  
 var newlang = ["JavaScript", "Rust"];  
 var join = lang.concat(newlang); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Output
New array: PHP, Python, Java, C, JavaScript, Rust
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;11: Array slice() Method&lt;/strong&gt;&lt;br&gt;
The js slice() array() method is used to selected elements in an array and make a new one. It can take one or two arguments.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var lang = ["PHP", "Python", "Java", "C", "JavaScript"];
 var lang = cars.slice(1, 4); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Output 
New Array : Python, JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;12: Array filter() Method&lt;/strong&gt;&lt;br&gt;
The js filter() method is used to filter the array, according our conditions.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;function isCheck(value) {&amp;lt;br&amp;gt;
  return value &amp;lt; 10;&amp;lt;br&amp;gt;
}

var filter = [10, 5, 16, 4, 7, 12].filter(isCheck);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
 //new array: 5,4,7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example the function filter() creates a new array. Those elements that satisfy the condition checked by isCheck() function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13: Array find() Method&lt;/strong&gt;&lt;br&gt;
The js find() method is used find the first element of an array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isCheck(value) {
  return value &amp;gt;= 10;
}
var find= [10, 5, 16, 4, 7, 12].find(isCheck);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
// 12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;14: Array forEach() Method&lt;/strong&gt;&lt;br&gt;
The JavaScript Array forEach method permits the call of a function on each element of an array in an easy way.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; var num = [18, 12, 10, 15];
 num.forEach(function(item) {
    document.writeln(item);
 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
 // return 
18 12 10 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;15: Array map() Method&lt;/strong&gt;&lt;br&gt;
The js map() method, creates an array by calling a specific function on each element in the original array.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var numbers = [4, 9, 16, 25];
var x = numbers.map(Math.sqrt);
document.write(x);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Output
 // return   
 2,3,4,5 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;16: Array reduce() Method&lt;/strong&gt;&lt;br&gt;
The javascript array reduce() method reduces the array to a single value.&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var numArr = [
        {  name: 'a', num: 50},
        {  name: 'b', num: 50},
        {  name: 'c', num: 75},
        {  name: 'd', num: 35},
        {  name: 'e', num: 25 },
        {  name: 'f', num: 40 },
    ];

    var sum = numArr.reduce(function (total, currentValue) {
        return total + currentValue.num;
    }, 0);

    document.write( "javascript- Sum of the array value is :- " + sum );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
 // return   
 275
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;17: Array some() Method&lt;/strong&gt;&lt;br&gt;
The javascript array some() method checks whether at least one element of the array matches the given predicate. if none of the array elements match the predicate, then it will return false&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var nums = [3, 18, 19, 20, 25];

function checkNumber(num) {
  return num &amp;gt;= 25;
}

document.write(nums.some(checkNumber));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output
 // return   
 True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;18: Array every() Method&lt;/strong&gt;&lt;br&gt;
The javascript array every() method checks whether all elements of the array match the predicate:&lt;/p&gt;

&lt;p&gt;Ex:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var nums = [3, 18, 19, 20, 25];

function checkNumber(num) {
  return num &amp;gt;= 3;
}

document.write(nums.every(checkNumber));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // return   
 true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;19: findIndex() Array Method&lt;/strong&gt;&lt;br&gt;
The javascript findIndex() method is used to find first occurrence position from an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1, 2, 3, 4, 5];

let res = numbers.findIndex(e =&amp;gt; e % 2 == 1);

document.write(res); //
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // return   
 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;20: Array include() Method&lt;/strong&gt;&lt;br&gt;
The js includes() method returns true if an javascript array contains a given element; Otherwise, it returns false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,2,3].includes(2); // true
[1,2,3].includes(4); // false
[1,2,3].includes(1,1); // false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // return   
 true
 false
 false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;21: indexOf() Array Method&lt;/strong&gt;&lt;br&gt;
The js array indexOf() method is used to find the first occurrence position of an array And returns the index of the first occurrence of the element. If the element is not found, -1 return.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr = [10, 20, 30, 40, 50, 70, 10, 50];
document.write(arr.indexOf(10)); // 0
document.write(arr.indexOf(10)); // 4
document.write(arr.indexOf(10)); // 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // return   
0
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;22: Array lastIndexOf() Method&lt;/strong&gt;&lt;br&gt;
This is similar to the indexOf() method, but one difference in these. The Javascript array lastIndexOf() method is used to find the last occurrence position of an array. It returns -1 if it cannot find the element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr = [10, 20, 30, 40, 50, 70, 10, 40];
document.write(arr.lastIndexOf(10)); // 6
document.write(arr.lastIndexOf(40)); // 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; // return   
6
7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;23: JavaScript Array isArray() Method&lt;/strong&gt;&lt;br&gt;
The javascript array isArray() method is used to check whether an object is an array. This function returns true if the object is an array, otherwise return false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var arr = [5, 3, 10, 1, 6, 12]

document.write("Retrun value = " + Array.isArray(arr)); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result of the above example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Retrun value = true  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>emptystring</category>
    </item>
  </channel>
</rss>
