Skip to content

Instantly share code, notes, and snippets.

View NallaRK's full-sized avatar

Ramakrishna Nalla NallaRK

View GitHub Profile
@NallaRK
NallaRK / Array CheatSheet.md
Created January 12, 2025 17:11 — forked from ajeetkumarrauniyar/Array CheatSheet.md
Cheat sheet of Array methods in JavaScript

Array Methods Cheat Sheet

1. push()

  • Definition: Adds one or more elements to the end of an array and returns the new length of the array.
  • Syntax: array.push(element1[, ...[, elementN]])
  • Example:
    let arr = [1, 2, 3];
    arr.push(4, 5);

console.log(arr); // Output: [1, 2, 3, 4, 5]

@NallaRK
NallaRK / falttenJSObject.js
Created May 9, 2024 08:59
Flatten a Nested Object in JavaScript
const flattenObject = (input, keyName) => {
var result = {};
for (const key in input) {
const newKey = keyName ? `${keyName}_${key}` : key;
if (typeof input[key] === "object" && !Array.isArray(input[key])) {
result = {...result, ...flattenObject(input[key], newKey)}
} else {
result[newKey] = input[key];
}
}