[Javascript] someJavascript (Array)

  1. Include Scripts
  2. #script src="myscript.js"##/script# >>> Before closing body tag

  3. Closure
  4. A closure is a function nested inside an outer function that retains access to variables declared in the outer function

                  const add = (function () {
                    let count = 0;
                    const nested = function () {
                      return (count = count + 1);
                    };
                    return nested;
                  })();
            
                  alert(add());
                
  5. Create Arrays

                let myArray = [];
                myArray[0] = "a";
                myArray[1] = "b";
                myArray[2] = "c";
          
                myArray.forEach((element) => {
                  alert(element);
                });
              
  6. myArray.join("&") >>> unite all elements in an array with a seprator
  7. myArray.pop() >>> Delete the last elements and returns its value
  8. myArray.push("myString") >>> To add an element and return the length
  9. shift(delete) and unshift(add) >>> have similar function as pop/push but it's on the first element instead
  10. myArray.reverse() >>> To reverse/
  11. myArray.slice(1,3) >>> To slice an array, similar to that of python
  12. myArray.sort().reverse().sort() >>> To sort an array

Source: ---


Disclaimer: The information in this webpage is shared by anonymous users from external online sources. We cannot guarantee its accuracy or truthfulness. Users should exercise caution and verify information independently.


© 2023 sunnypeaceisland.com