<?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>Forem: T Shiva Kumar</title>
    <description>The latest articles on Forem by T Shiva Kumar (@t_shivakumar_0dc86c6486c).</description>
    <link>https://forem.com/t_shivakumar_0dc86c6486c</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%2F1916078%2Fc929b969-ec00-4c8b-9e42-d6918d787743.png</url>
      <title>Forem: T Shiva Kumar</title>
      <link>https://forem.com/t_shivakumar_0dc86c6486c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/t_shivakumar_0dc86c6486c"/>
    <language>en</language>
    <item>
      <title>Getting Started With React</title>
      <dc:creator>T Shiva Kumar</dc:creator>
      <pubDate>Tue, 03 Sep 2024 16:21:15 +0000</pubDate>
      <link>https://forem.com/t_shivakumar_0dc86c6486c/getting-started-with-react-1m07</link>
      <guid>https://forem.com/t_shivakumar_0dc86c6486c/getting-started-with-react-1m07</guid>
      <description>&lt;h2&gt;
  
  
  Here’s a detailed guide on how to install and set up a React project:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. Install Node.js and npm
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Node.js&lt;/strong&gt; is a JavaScript runtime that allows you to run JavaScript on the server side, and npm (Node Package Manager) is a tool for managing packages (libraries) for Node.js.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Download and install Node.js&lt;/strong&gt; from &lt;a href="https://nodejs.org/en" rel="noopener noreferrer"&gt;Node.js official website. &lt;/a&gt;The installation includes npm, so you don't need to install npm separately.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify installation:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v
npm -v

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands should print the versions of Node.js and npm if the installation was successful.&lt;br&gt;
&lt;strong&gt;2. Create a New React Project&lt;/strong&gt;&lt;br&gt;
 &lt;strong&gt;Using npx (recommended):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux).&lt;/li&gt;
&lt;li&gt;Run the following command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-react-app

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Replace &lt;strong&gt;my-react-app **with your desired project name. This command uses **npx&lt;/strong&gt; to run &lt;strong&gt;create-react-app&lt;/strong&gt; without installing it globally.&lt;/p&gt;
&lt;h2&gt;
  
  
  3. Navigate to Your Project Directory
&lt;/h2&gt;

&lt;p&gt;Change to your project folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd my-react-app

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Start the Development Server
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Run the development server:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command starts the development server and opens your application in the default web browser at &lt;strong&gt;&lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;.&lt;/strong&gt; The server will automatically reload the page whenever you make changes to the source code.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Explore the Folder Structure
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Here’s a breakdown of the folder structure created by create-react-app:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;public/&lt;/strong&gt;: Contains static files that are served directly by the server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;index.html:&lt;/strong&gt; The main HTML file where your React app is injected.&lt;br&gt;
 &lt;strong&gt;favicon.ico:&lt;/strong&gt;The icon displayed in the browser tab.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;src/:&lt;/strong&gt; Source code of the React app.&lt;br&gt;
 &lt;strong&gt;index.js:&lt;/strong&gt; Entry point that renders the root component.&lt;br&gt;
&lt;strong&gt;App.js:&lt;/strong&gt; Main React component to edit and display content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;node_modules/:&lt;/strong&gt; Installed npm packages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;package.json:&lt;/strong&gt; Project metadata, dependencies, and scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;package-lock.json:&lt;/strong&gt; Locks dependency versions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;.gitignore:&lt;/strong&gt; Files and directories to be ignored by Git.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;README.md:&lt;/strong&gt; Documentation for your project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a React Component
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React components can be either class-based or function-based. Function components are more common, especially with the use of Hooks.
&lt;strong&gt;Here's an example of a simple function component:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello, React!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This component returns some JSX, which looks like HTML but is actually JavaScript.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Promises in java script</title>
      <dc:creator>T Shiva Kumar</dc:creator>
      <pubDate>Tue, 20 Aug 2024 07:17:02 +0000</pubDate>
      <link>https://forem.com/t_shivakumar_0dc86c6486c/promises-in-java-script-125a</link>
      <guid>https://forem.com/t_shivakumar_0dc86c6486c/promises-in-java-script-125a</guid>
      <description>&lt;h2&gt;
  
  
  what is promises
&lt;/h2&gt;

&lt;p&gt;*A Promises is an object representing the eventual completion of an asynchronous operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  States of a Promise
&lt;/h2&gt;

&lt;h2&gt;
  
  
  A Promise can be in one of three states:
&lt;/h2&gt;

&lt;p&gt;1.Pending: The initial state, neither fulfilled nor rejected.&lt;br&gt;
2.Fulfilled: The operation completed successfully.&lt;br&gt;
3.Rejected: The operation failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Promise
&lt;/h2&gt;

&lt;p&gt;let myPromise = new Promise((resolve, reject) =&amp;gt; {&lt;br&gt;
  let success = true;&lt;br&gt;
  if (success) {&lt;br&gt;
    resolve("Operation was successful!");&lt;br&gt;
  } else {&lt;br&gt;
    reject("Operation failed.");&lt;br&gt;
  }&lt;br&gt;
});&lt;/p&gt;

&lt;h2&gt;
  
  
  To handle the outcome of a promise, you use the then() and catch() methods:
&lt;/h2&gt;

&lt;p&gt;myPromise&lt;br&gt;
  .then((message) =&amp;gt; {&lt;br&gt;
    console.log(message); // "Operation was successful!"&lt;br&gt;
  })&lt;br&gt;
  .catch((error) =&amp;gt; {&lt;br&gt;
    console.error(error); // "Operation failed."&lt;br&gt;
  });&lt;/p&gt;

&lt;p&gt;*then() is executed when the promise is fulfilled.&lt;br&gt;
*catch() is executed when the promise is rejected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of promises
&lt;/h2&gt;

&lt;p&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(() =&amp;gt; {

    resolve("Promise fulfilled!");
}, 2000); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;myPromise&lt;br&gt;
    .then(message =&amp;gt; {&lt;br&gt;
        console.log(message); &lt;br&gt;
    })&lt;br&gt;
    .catch(error =&amp;gt; {&lt;br&gt;
        console.error('There has been a problem with the promise:', error);&lt;br&gt;
    });&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Promises:-
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1.Improved Readability:
&lt;/h2&gt;

&lt;p&gt;Promises allow for cleaner and more linear code compared to nested callbacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.Better Error Handling:
&lt;/h2&gt;

&lt;p&gt;Errors can be handled using a dedicated .catch() method, simplifying error management.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.Avoids Callback Hell:
&lt;/h2&gt;

&lt;p&gt;Promises help prevent deeply nested structures, making the code easier to read and maintain.&lt;/p&gt;

&lt;h2&gt;
  
  
  4.Supports Async/Await:
&lt;/h2&gt;

&lt;p&gt;Promises are the foundation for the async/await syntax, allowing asynchronous code to be written in a synchronous style.&lt;/p&gt;

&lt;h2&gt;
  
  
  5.Enhanced Performance:
&lt;/h2&gt;

&lt;p&gt;Promises can improve performance by allowing multiple asynchronous operations to run concurrently.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Higher-order function in java script</title>
      <dc:creator>T Shiva Kumar</dc:creator>
      <pubDate>Sat, 17 Aug 2024 11:19:41 +0000</pubDate>
      <link>https://forem.com/t_shivakumar_0dc86c6486c/higher-order-function-in-java-script-21e5</link>
      <guid>https://forem.com/t_shivakumar_0dc86c6486c/higher-order-function-in-java-script-21e5</guid>
      <description>&lt;h2&gt;
  
  
  What is higher-order function?
&lt;/h2&gt;

&lt;p&gt;A higher-order function is a function that does at least one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Takes one or more functions as arguments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Returns a function as its result.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why Use Higher-Order Functions?
&lt;/h2&gt;

&lt;p&gt;Higher-order functions provide several benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reusability:They allow you to create more generic functions that can be reused with different behaviors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modularity:They help in breaking down complex problems into smaller, manageable functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cleaner Code: Code written with higher-order functions is often more concise and easier to read.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Higher-Order Functions in JavaScript
&lt;/h2&gt;

&lt;p&gt;1.map: This function creates a new array by applying a function to each element of the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4];
const doubled = numbers.map(num =&amp;gt; num * 2);
console.log(doubled); // Output: [2, 4, 6, 8]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, map() is a higher-order function because it takes a function (num =&amp;gt; num * 2) as an argument.&lt;/p&gt;

&lt;p&gt;2.filter: This function creates a new array with all elements that pass the test implemented by the provided function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter(num =&amp;gt; num % 2 === 0);
console.log(evenNumbers); // [2, 4]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, filter() uses the provided function to determine which elements should be included in the new array.&lt;/p&gt;

&lt;p&gt;3.reduce: This function applies a function against an accumulator and each element in the array to reduce it to a single value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4];
const sum = numbers.reduce((acc, num) =&amp;gt; acc + num, 0);
console.log(sum); // 10

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;reduce() is a higher-order function that lets you accumulate a result based on the function you pass in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Higher-Order Functions
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function higherOrderFunction(callback) {
  console.log("Executing the higher-order function...");
  callback();
}

function callbackFunction() {
  console.log("Executing the callback function...");
}

higherOrderFunction(callbackFunction);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example: Function Returning a Function
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createMultiplier(multiplier) {
  return function(num) {
    return num * multiplier;
  };
}

const double = createMultiplier(2);
const triple = createMultiplier(3);

console.log(double(5)); // 10
console.log(triple(5)); // 15

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Combining Higher-Order Functions
&lt;/h2&gt;

&lt;p&gt;One of the powerful aspects of higher-order functions is that they can be combined to perform complex operations concisely.&lt;br&gt;
&lt;/p&gt;

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

const result = numbers
  .filter(num =&amp;gt; num % 2 === 0) // Get even numbers: [2, 4, 6]
  .map(num =&amp;gt; num * 2)          // Double them: [4, 8, 12]
  .reduce((sum, num) =&amp;gt; sum + num, 0); // Sum them up: 24

console.log(result); // 24

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Higher-order functions are a fundamental concept in JavaScript, enabling you to write more abstract, reusable, and powerful code. By understanding and using higher-order functions, you can take your JavaScript skills to the next level, making your code cleaner, more efficient, and more maintainable.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>String methods in javascript</title>
      <dc:creator>T Shiva Kumar</dc:creator>
      <pubDate>Wed, 14 Aug 2024 11:09:51 +0000</pubDate>
      <link>https://forem.com/t_shivakumar_0dc86c6486c/string-methods-in-javascript-516p</link>
      <guid>https://forem.com/t_shivakumar_0dc86c6486c/string-methods-in-javascript-516p</guid>
      <description>&lt;h2&gt;
  
  
  What is a String?
&lt;/h2&gt;

&lt;p&gt;*The sequence of one or more characters enclosed within quotation marks is called a string.&lt;br&gt;
*The quotation can be single quotes '' or double quotes " " or backtick ``.&lt;br&gt;
And, the sequence of characters can be alphabets, numbers, symbols, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  String methods
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1.charAt(index)
&lt;/h2&gt;

&lt;p&gt;*The charAt() returns the character at a specified index in a string.&lt;br&gt;
*The very first character of the string has an index of 0, the second character has index 1, and so on...&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO";&lt;br&gt;
let char = text.charAt(0); &lt;br&gt;
console.log(char)// Returns "H"&lt;/p&gt;

&lt;h2&gt;
  
  
  2.length
&lt;/h2&gt;

&lt;p&gt;*This property returns the number of characters in a string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO";&lt;br&gt;
let length = text.length;&lt;br&gt;
console.log(length) // Returns 5&lt;/p&gt;

&lt;h2&gt;
  
  
  3.slice(start, end)
&lt;/h2&gt;

&lt;p&gt;*Extracts a section of a string and returns it as a new string. The start index is inclusive, while the end index is exclusive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let part = text.slice(0, 5);&lt;br&gt;
console.log(part) // Returns "HELLO"&lt;/p&gt;

&lt;h2&gt;
  
  
  4.substring(start, end)
&lt;/h2&gt;

&lt;p&gt;*Similar to slice(), but treats negative indices as 0. It extracts characters between two specified indices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let part = text.substring(0, 5); &lt;br&gt;
console.log(part)// Returns "HELLO"&lt;/p&gt;

&lt;h2&gt;
  
  
  5.toUpperCase()
&lt;/h2&gt;

&lt;p&gt;*Converts all characters in a string to uppercase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "hello";&lt;br&gt;
let upper = text.toUpperCase(); &lt;br&gt;
console.log(upper)// Returns "HELLO"&lt;/p&gt;

&lt;h2&gt;
  
  
  6.toLowerCase()
&lt;/h2&gt;

&lt;p&gt;*Converts all characters in a string to lowercase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO";&lt;br&gt;
let lower = text.toLowerCase(); &lt;br&gt;
console.log(lower)// Returns "hello"&lt;/p&gt;

&lt;h2&gt;
  
  
  7.trim()
&lt;/h2&gt;

&lt;p&gt;*Removes whitespace from both ends of a string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "   hello   ";&lt;br&gt;
let trimmed = text.trim();&lt;br&gt;
console.log(trimmed) // Returns "hello"&lt;/p&gt;

&lt;h2&gt;
  
  
  8.concat()
&lt;/h2&gt;

&lt;p&gt;*Joins two or more strings and returns a new string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text1 = "Hello";&lt;br&gt;
let text2 = "World";&lt;br&gt;
let combined = text1.concat(" ", text2);&lt;br&gt;
console.log(combined) // Returns "Hello World"&lt;/p&gt;

&lt;h2&gt;
  
  
  9.indexOf(substring)
&lt;/h2&gt;

&lt;p&gt;*Returns the index of the first occurrence of a specified substring. Returns -1 if not found.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let index = text.indexOf("O"); &lt;br&gt;
console.log(index)// Returns 4&lt;/p&gt;

&lt;h2&gt;
  
  
  10.replace(searchValue, newValue)
&lt;/h2&gt;

&lt;p&gt;*Replaces the first occurrence of a specified value with a new value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let newText = text.replace("WORLD", "EVERYONE");&lt;br&gt;
 console.log(newText)// Returns "HELLO EVERYONE"&lt;/p&gt;

&lt;h2&gt;
  
  
  11.replaceAll(searchValue, newValue)
&lt;/h2&gt;

&lt;p&gt;*Replaces all occurrences of a specified value with a new value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD WORLD";&lt;br&gt;
let newText = text.replaceAll("WORLD", "EVERYONE");&lt;br&gt;
 console.log(newText)// Returns "HELLO EVERYONE EVERYONE"&lt;/p&gt;

&lt;h2&gt;
  
  
  12.split(separator)
&lt;/h2&gt;

&lt;p&gt;*Splits a string into an array of substrings based on a specified separator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let parts = text.split(" ");&lt;br&gt;
 console.log(parts)// Returns ["HELLO", "WORLD"]&lt;/p&gt;

&lt;h2&gt;
  
  
  13.join(separator)
&lt;/h2&gt;

&lt;p&gt;*Joins the elements of an array into a string, using a specified separator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let array = ["HELLO", "WORLD"];&lt;br&gt;
let joined = array.join(" ");&lt;br&gt;
  console.log(joined)// Returns "HELLO WORLD"&lt;/p&gt;

&lt;h2&gt;
  
  
  14.startsWith(searchString)
&lt;/h2&gt;

&lt;p&gt;*Checks if the string starts with the specified string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let starts = text.startsWith("HELLO");&lt;br&gt;
 console.log(starts)// Returns true&lt;/p&gt;

&lt;h2&gt;
  
  
  15.endsWith(searchString)
&lt;/h2&gt;

&lt;p&gt;*Checks if the string ends with the specified string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let ends = text.endsWith("WORLD");&lt;br&gt;
  console.log(ends)// Returns true&lt;/p&gt;

&lt;h2&gt;
  
  
  16.includes(searchString)
&lt;/h2&gt;

&lt;p&gt;*Checks if the string contains the specified substring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let text = "HELLO WORLD";&lt;br&gt;
let includes = text.includes("LO"); &lt;br&gt;
 console.log(includes)// Returns true&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Array methods in javascript.</title>
      <dc:creator>T Shiva Kumar</dc:creator>
      <pubDate>Tue, 13 Aug 2024 10:57:18 +0000</pubDate>
      <link>https://forem.com/t_shivakumar_0dc86c6486c/array-methods-in-javascript-565h</link>
      <guid>https://forem.com/t_shivakumar_0dc86c6486c/array-methods-in-javascript-565h</guid>
      <description>&lt;h2&gt;
  
  
  There are some methods in array
&lt;/h2&gt;

&lt;p&gt;1.push()&lt;br&gt;
2.unshift()&lt;br&gt;
3.pop()&lt;br&gt;
4.shift()&lt;br&gt;
5.splice()&lt;br&gt;
6.slice()&lt;br&gt;
7.indexOf()&lt;br&gt;
8.includes()&lt;br&gt;
9.forEach()&lt;br&gt;
10.map()&lt;br&gt;
11.filter()&lt;br&gt;
12.find()&lt;br&gt;
13.some()&lt;br&gt;
14.every()&lt;br&gt;
15.concat()&lt;br&gt;
16.join()&lt;br&gt;
17.sort()&lt;br&gt;
18.reduce()&lt;/p&gt;

&lt;h2&gt;
  
  
  1 Push() method
&lt;/h2&gt;

&lt;p&gt;*Add new element at last position.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.push(element1, element2, ..., elementN)&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let fruits = ['apple', 'banana'];&lt;br&gt;
let newLength = fruits.push('orange', 'mango');&lt;/p&gt;

&lt;p&gt;console.log(fruits); // Output: ['apple', 'banana', 'orange', 'mango']&lt;br&gt;
console.log(newLength); // Output: 4&lt;/p&gt;

&lt;h2&gt;
  
  
  2 unshift() method
&lt;/h2&gt;

&lt;p&gt;*Add new element at initial position. &lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.unshift(item1, item2, ..., itemN)&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const fruits = ["Banana", "Orange", "Apple"];&lt;br&gt;
fruits.unshift("Lemon");&lt;br&gt;
console.log(fruits); // Output: ["Lemon", "Banana", "Orange", "Apple"]&lt;/p&gt;

&lt;h2&gt;
  
  
  3 pop() method
&lt;/h2&gt;

&lt;p&gt;*It will remove your last element.&lt;br&gt;
*It will return the removed element from the array&lt;br&gt;
*"undifined" if the array is empty&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.pop();&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const fruits = ['Apple', 'Banana', 'Cherry'];&lt;br&gt;
const lastFruit = fruits.pop();&lt;br&gt;
console.log(fruits); // Output: ['Apple', 'Banana']&lt;br&gt;
console.log(lastFruit); // Output: 'Cherry'&lt;/p&gt;

&lt;h2&gt;
  
  
  4 shift() method
&lt;/h2&gt;

&lt;p&gt;*It will remove your first element.&lt;br&gt;
*It will return the removed element from the array&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.shift();&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const fruits = ['Apple', 'Banana', 'Cherry'];&lt;br&gt;
const firstFruit = fruits.shift();&lt;br&gt;
console.log(fruits); // Output: ['Banana', 'Cherry']&lt;br&gt;
console.log(firstFruit); // Output: 'Apple'&lt;/p&gt;

&lt;h2&gt;
  
  
  5 splice() method
&lt;/h2&gt;

&lt;p&gt;*Adds or remove elements from an array.&lt;br&gt;&lt;br&gt;
*splice() will modified original array.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.splice(start, deleteCount, item1, item2, ...);&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let colors = ['Red', 'Green', 'Blue'];&lt;br&gt;
colors.splice(1, 0, 'Yellow', 'Pink'); // Adds 'Yellow' and 'Pink' at index 1&lt;br&gt;
console.log(colors); // Output: ['Red', 'Yellow', 'Pink', 'Green', 'Blue']&lt;/p&gt;

&lt;h2&gt;
  
  
  6 slice() method
&lt;/h2&gt;

&lt;p&gt;*It is used to extract(give) the part of array.&lt;br&gt;
*slice will return array.&lt;br&gt;
*slice will not modified the original array.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.slice(start, end);&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let numbers = [2, 3, 5, 7, 11, 13, 17];&lt;br&gt;
let newArray = numbers.slice(3, 6);&lt;br&gt;
console.log(newArray); // Output: [7, 11, 13]&lt;/p&gt;

&lt;h2&gt;
  
  
  7 indexOf() method
&lt;/h2&gt;

&lt;p&gt;*The indexOf() method in JavaScript is used to find the first index at which a given element can be found in the array, or -1 if the element is not present.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.indexOf(searchElement, fromIndex);&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let fruits = ['Apple', 'Banana', 'Orange', 'Banana'];&lt;br&gt;
let index = fruits.indexOf('Banana');&lt;br&gt;
console.log(index); // Output: 1&lt;/p&gt;

&lt;h2&gt;
  
  
  8 includes() method
&lt;/h2&gt;

&lt;p&gt;*It is used to identify certain element is present in our array or not.&lt;br&gt;
*If element is present it will return "true" otherwise return "false".&lt;br&gt;
*It will return boolean value.&lt;/p&gt;

&lt;h2&gt;
  
  
  syntax
&lt;/h2&gt;

&lt;p&gt;array.includes(searchElement, fromIndex);&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let numbers = [1, 2, 3, 4, 5];&lt;br&gt;
let hasThree = numbers.includes(3, 2);&lt;br&gt;
console.log(hasThree); // Output: true&lt;/p&gt;

&lt;h2&gt;
  
  
  9 forEach() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Executes the function for each element.&lt;/li&gt;
&lt;li&gt;Does not create a new array.&lt;/li&gt;
&lt;li&gt;Original array remains unchanged.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let numbers = [1, 2, 3];&lt;br&gt;
numbers.forEach((value, index, arr) =&amp;gt; {&lt;br&gt;
  arr[index] = value * 2;&lt;br&gt;
});&lt;br&gt;
console.log(numbers); // Output: [2, 4, 6]&lt;/p&gt;

&lt;h2&gt;
  
  
  10 map() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It takes each element of an array.&lt;/li&gt;
&lt;li&gt;The output of map array is always array only.&lt;/li&gt;
&lt;li&gt;It will not change original array&lt;/li&gt;
&lt;li&gt;Creates a new array.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const numbers = [10, 20, 30];&lt;br&gt;
const incremented = numbers.map((num, index) =&amp;gt; num + index);&lt;br&gt;
console.log(incremented); // Output: [10, 21, 32]&lt;/p&gt;

&lt;h2&gt;
  
  
  11 filter() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is used to filter elements or data from the array based on certain condition.

&lt;ul&gt;
&lt;li&gt;If it return 'true' what ever data is store in this parameter that data will return.&lt;/li&gt;
&lt;li&gt;If it return 'false' then it will not return any value it returns empty array&lt;/li&gt;
&lt;li&gt;Creates a new array.&lt;/li&gt;
&lt;li&gt;Original array remains unchanged.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const numbers = [1, 2, 3, 4, 5, 6];&lt;br&gt;
const evenNumbers = numbers.filter(num =&amp;gt; num % 2 === 0);&lt;br&gt;
console.log(evenNumbers); // Output: [2, 4, 6]&lt;/p&gt;

&lt;h2&gt;
  
  
  12 find() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It returns the first element of array for which call back function return true.

&lt;ul&gt;
&lt;li&gt;It return 'undifined' if the element is false or not satisfies.&lt;/li&gt;
&lt;li&gt;Original array remains unchanged.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const numbers = [1, 3, 4, 9, 8];&lt;/p&gt;

&lt;p&gt;function isEven(element) {&lt;br&gt;
  return element % 2 === 0;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;const firstEven = numbers.find(isEven);&lt;br&gt;
console.log(firstEven); // Output: 4&lt;/p&gt;

&lt;h2&gt;
  
  
  13 some() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Returns true if at least one element passes the test.&lt;/li&gt;
&lt;li&gt;Returns false if no elements pass the test.&lt;/li&gt;
&lt;li&gt;Stops testing once the first passing element is found.
*Original array remains unchanged.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const numbers = [2, 4, 6, 8, 10];&lt;/p&gt;

&lt;p&gt;const hasGreaterThanFive = numbers.some(num =&amp;gt; num &amp;gt; 5);&lt;br&gt;
console.log(hasGreaterThanFive); // Output: true&lt;/p&gt;

&lt;h2&gt;
  
  
  14 every() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It test all the elements in the array if all the condition satisfy 
 then 
it return true.&lt;/li&gt;
&lt;li&gt;If one condition is not satisfy then it return false.&lt;/li&gt;
&lt;li&gt;Original array remains unchanged.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const numbers = [10, 20, 30, 40, 50];&lt;/p&gt;

&lt;p&gt;const allGreaterThanFive = numbers.every(num =&amp;gt; num &amp;gt; 5);&lt;br&gt;
console.log(allGreaterThanFive); // Output: true&lt;/p&gt;

&lt;h2&gt;
  
  
  15 concat() method
&lt;/h2&gt;

&lt;p&gt;*Combine two or more arrays and returns a new array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const fruits = ['Apple', 'Banana'];&lt;br&gt;
const vegetables = ['Carrot', 'Peas'];&lt;br&gt;
const grains = ['Rice', 'Wheat'];&lt;/p&gt;

&lt;p&gt;const food = fruits.concat(vegetables, grains);&lt;br&gt;
console.log(food); // Output: ['Apple', 'Banana', 'Carrot', 'Peas', 'Rice', 'Wheat']&lt;/p&gt;

&lt;h2&gt;
  
  
  16 join() method
&lt;/h2&gt;

&lt;p&gt;*Create a new string by concatenating all the elements of an array and&lt;br&gt;
return a string by a specified separator.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;const letters = ['J', 'o', 'i', 'n'];&lt;br&gt;
const result = letters.join('');&lt;br&gt;
console.log(result); // Output: 'Join'&lt;/p&gt;

&lt;h2&gt;
  
  
  17 sort() method
&lt;/h2&gt;

&lt;p&gt;*It is used to arrange the element of an array in place and return the sorted array.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By default the sort method sorts the element as strings in ascending order.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example1
&lt;/h2&gt;

&lt;p&gt;const numbers = [4, 2, 5, 1, 3];&lt;br&gt;
numbers.sort((a, b) =&amp;gt; a - b);&lt;br&gt;
console.log(numbers); // Output: [1, 2, 3, 4, 5]&lt;/p&gt;

&lt;h2&gt;
  
  
  Example2
&lt;/h2&gt;

&lt;p&gt;const numbers = [4, 2, 5, 1, 3];&lt;br&gt;
numbers.sort((a, b) =&amp;gt; b - a);&lt;br&gt;
console.log(numbers); // Output: [5, 4, 3, 2, 1]&lt;/p&gt;

&lt;h2&gt;
  
  
  18 reduce() method
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;perform some operations and reduce the array to a single value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;let number = [1, 2, 3, 4, 5];&lt;br&gt;
let sum = number.reduce((accumulator, currentValue) =&amp;gt; {&lt;br&gt;
  return accumulator + currentValue;&lt;br&gt;
}, 0);&lt;/p&gt;

&lt;p&gt;console.log(sum); &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
