Javascript Hacks with ES6-ES7

    let x = [3,4,5,6,7,null,null,6,8];
    
    // immutable 
    let y = x.filter(function(item,index){
         return item
    });
    
    
    x.forEach(function(item,index){
         // iterate elm
    });
    let x = "login login";
    console.log(x.replace("in","out")); //  logout login
    
    // logout login
    x.replace(/in/g, "out"); // logout logout 
    
    var array = [1,2,3,4,5,6];
    array.length 
    
    
    var veg2 = ["x1", "x2", "x3","x1","x2"];
    
    veg2.filter(function(item, index,array){
         return array.find(item) === index 
    })
    
    
    
    
    var x = [1,2,1,4,5,5,6];
        // 1,2,3,4,
    
    x.filter(function(item, index,array){
         return array.indexOf(item) === index;
    });
    
    
    var x1 = [4,5,6,7];
    var x2 = [6,7,8,9];
    
    var x3 = [...x1, ...x2];
    [... new Set(x3)];
    
    
    var x = "hello world";
    
    console.log(x.split('').reverse().join(''));
tarun6:023 months ago
    
    var x = {
        a:60,
        b:70
    }
    
    console.log(x)
tarun7:553 months ago
    const obj = { foo: 'bar', baz: 42 };
    console.log(Object.entries(obj))
    
    var array = [4,5,6,7];
    
    
    /*
    .forEach(([key, value]) => console.log(`${key}: ${value}`)); // "
    
    console.log(Object.keys(obj))
    Object.keys(obj).map(function(item){return item});
    Object.entries(obj).forEach(item =>  console.log(item) );
    
    */
tarun5:323 months ago
    var copiedObject = jQuery.extend({}, originalObject)
    
    var cloneOfA = JSON.parse(JSON.stringify(a));
    
    
    let objClone = { ...obj };
    var x = {a:70, b:80 , c : {g :90}};
    
    var y = Object.assign({}, x);
    
    
    
tarun4:253 months ago
    function clone(obj){
      var objCopy = {};
      for(var i in obj){
          if(typeof i === "Object"){
              objCopy[i]= clone(i)
          } else {
          objCopy[i] = obj[i]
        }
      }
       return objCopy; 
    }
    
    console.log(clone({x:90, y:{z:80}}));
    
tarun1:113 months ago
    
    (function(a,b){
           return a+b;
    })(3,4)
    
    function checkArray(arr){
          return 
    }
    
    var obj = {};
    var obj1 = [];
    
    let x = [4,5,6,7,8,8];
    
    let y = Object.assign({}, {x:80});
    x.slice(0);
    [...x];
    
    
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    
    
    var object  = {
        a : 50,
        b: 60
    }
    var x = JSON.parse(JSON.stringify(object));
    console.log(x);
    
    // timer methods from web API 
    
    setTimeout(function(){
        console.log('after 5 sec');
    }, 5000);
    // Array.prototype.shift
    const numbers = [1, 2, 3, 4, 5]
    // With shift
    const firstNumber = numbers.shift()
    console.log(firstNumber) // 1
    console.log(numbers) // [2, 3, 4, 5]
    
    // Without shift
    const [firstNumber, ...numbersWithoutOne] = [1, 2, 3, 4, 5]
    // numbersWithoutOne = [2, 3, 4, 5]
    
    console.log(firstNumber) // 1
    console.log(numbersWithoutOne) // [2, 3, 4, 5]
    
    // Array.prototype.shift
    const numbers = [1, 2, 3, 4, 5]
    // With shift
    const firstNumber = numbers.shift()
    console.log(firstNumber) // 1
    console.log(numbers) // [2, 3, 4, 5]
    
    // Without shift
    const [firstNumber, ...numbersWithoutOne] = [1, 2, 3, 4, 5]
    // numbersWithoutOne = [2, 3, 4, 5]
    
    console.log(firstNumber) // 1
    console.log(numbersWithoutOne) // [2, 3, 4, 5]
    
    // Array.prototype.shift
    const numbers = [1, 2, 3, 4, 5]
    // With shift
    const firstNumber = numbers.shift()
    console.log(firstNumber) // 1
    console.log(numbers) // [2, 3, 4, 5]
    
    // Without shift
    const [firstNumber, ...numbersWithoutOne] = [1, 2, 3, 4, 5]
    // numbersWithoutOne = [2, 3, 4, 5]
    
    console.log(firstNumber) // 1
    console.log(numbersWithoutOne) // [2, 3, 4, 5]
    
    // Array.prototype.shift
    const numbers = [1, 2, 3, 4, 5]
    // With shift
    const firstNumber = numbers.shift()
    console.log(firstNumber) // 1
    console.log(numbers) // [2, 3, 4, 5]
    
    // Without shift
    const [firstNumber, ...numbersWithoutOne] = [1, 2, 3, 4, 5]
    // numbersWithoutOne = [2, 3, 4, 5]
    
    console.log(firstNumber) // 1
    console.log(numbersWithoutOne) // [2, 3, 4, 5]
    
    const nodes = document.querySelectorAll('.todo-item')
    console.log(Array.isArray(nodes)) // false
    
    const todoItems = Array.from(nodes)
    console.log(Array.isArray(todoItems)) // true
    
    var x  = [6,7,8,9,0];
    x.slice(
    const potentialParticipants = [
      { id: 'k38i', name: 'john', age: 17 },
      { id: 'baf3', name: 'mary', age: 13 },
      { id: 'a111', name: 'gary', age: 24 },
      { id: 'fx34', name: 'emma', age: 34 },
    ];
    // join(',')
    
    potentialParticipants.filter(data => data.age > 18 ).map((data) => data.name ).join(',')
    'use strict';
    
    const characters = [
      'ironman',
      'black_widow',
      'hulk',
      'captain_america',
      'hulk',
      'thor',
    ];
    
    console.log(characters.indexOf('hulk'));
    // 2
    console.log(characters.indexOf('batman'));
    const numbers = [1, 2, 3]
    const otherNumbers = [4, 5, 6]
    const numbersConcatenated = numbers.concat(otherNumbers);
    const x = [ ... new Set(numbersConcatenated)];
    
    console.log(numbersConcatenated) // [1, 2, 3, 4, 5, 6]
    // You can merge as many arrays as you want
    function concatAll(arr, ...arrays) {
      return arr.concat(...arrays)
    }
    console.log(concatAll([1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]))
    
    
     // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
    const characters = [
      { id: 1, name: 'ironman' },
      { id: 2, name: 'black_widow' },
      { id: 3, name: 'captain_america' },
      { id: 4, name: 'captain_america' },
    ];
    function getCharacter(name) {
      return character => character.name === name;
    }
    console.log(characters.filter(getCharacter('captain_america')));
    // [
    //   { id: 3, name: 'captain_america' },
    //   { id: 4, name: 'captain_america' },
    // ]
    const characters = [
      { id: 1, name: 'ironman', env: 'marvel' },
      { id: 2, name: 'black_widow', env: 'marvel' },
      { id: 3, name: 'wonder_woman', env: 'marvel' },
    ];
    
    function hasCharacterFrom(env) {
      return character => character.env === env;
    }
    
    console.log(characters.find(hasCharacterFrom('marvel')));
    // { id: 1, name: 'ironman', env: 'marvel' }
    
    console.log(characters.every(hasCharacterFrom('marvel')));
    console.log("Hello from JavaScript");
    // single  liner codes
    const all = (arr, fn=Boolean) => arr.some(fn);
    all([0,0,0,0,5], x => x > 0);
    
    // how can we check all arrary elm are equal
    
    const allEqual = arr => arr.every(val => val === arr[0])
    
    allEqual([1,1,1,1,1,]);
    allEqual([1,2,3,4]);
    
    
    // [5,6,7,8,9,6,7,8,9];
    
    // single  liner codes
    const all = (arr, fn=Boolean) => arr.some(fn);
    all([0,0,0,0,5], x => x > 0);
    
    // how can we check all arrary elm are equal
    Array.prototype.
    const allEqual = arr => arr.every(val => val === arr[0])
    
    allEqual([1,1,1,1,1,]);
    allEqual([1,2,3,4]);
    
    
    // [5,6,7,8,9,6,7,8,9];
    
Javascript Hacks with ES6-ES7