fbpx
Programs

Programs

Data Science
  • Data Analytics Explore Data Analytics
  • Data Science Explore Data Science
  • Machine Learning Explore Machine Learning
Digital Course
  • Digital Marketing Explore Best Digital Marketing Course
  • SEO Explore Best SEO Course
Programming
  • Python Explore Python
  • Java Explore Java
Microsoft Office
  • Advanced Excel Explore Advanced Excel
Data Visualization Tool
  • Power BI Explore Power BI
  • Tableau Explore Tableau
Web Development
  • MERN Stack Explore MERN Stack
  • Django with Python Explore Django with Python
  • Web Designing Explore Web Designing

Spread and Rest Operator

spread-and-rest-operator

Table of Contents

Spread and Rest Operator- What’s the Difference?

SPREAD OPERATOR

The spread operator in Javascript, denoted by three dots (…), is a powerful addition to JavaScript. It serves as a tool to expand iterables, such as arrays or strings, in places where more than zero arguments are expected. Unlike the rest parameter, the spread operator cuttings values from an array. Let’s study the syntax and discover various use cases.

Syntax:

var variableName=[...value]

In this syntax, the three dots (…) mean the spread operator, pointing all values in the detailed variable.

Usage of Spread Operator in Different Cases

 1. Spread Operator and Array Manipulation

Constructing array literal

When creating an array using the literal form, the spread operator simplifies the insertion of another array within the initialized array.

let Numbers = ['1', '2'];

let new_Numbers = [... Numbers, '3', '4', '5']; 
console.log(new_Numbers);


Output:
['1', '2', '3', '4', '5']

Concatenating arrays

The spread operator can concatenate two or more arrays.

let arr1 = ['1', '2'];
let arr2 = ['3', '4', '5'];

let combine_arr = [...arr1, ...arr2]; 
console.log(combine_arr);

Output:
['1', '2', '3', '4', '5']

Replication an array

The spread operator enables copying the case of an array.

let arr1 = ['1', '2'];
let arr2 = [...arr1];

console.log(arr2);

//Output: [ '1', '2']

When replication arrays without the spread operator, implanting a new element in the replicated array affects the original array. However, using the spread operator confirms that the original array remains unaffected.

Without using a spread operator

let arr1 = ['1', '2'];
let arr2 = arr1; 
arr2.push('3'); 
console.log(arr2); 
console.log(arr1);


Output:
['1', '2','3']
['1','2', '3']

Using spread operator

let arr1 = ['1', '2'];
let arr2 = [...arr1];
arr2.push('3');
console.log(arr2);
console.log(arr1);

Output:
['1', '2','3']
['1','2']

Note: The spread operator performs a shallow copy, copying the array itself rather than its elements.

Spread Operator and Strings

The spread operator can also be useful to strings, spreading out each character into different elements.

let str = ['s', ...'PREA', 'D'];
console.log(str);

Output: [ 'S', 'P', 'R', 'E', 'A', 'D']

REST OPERATOR

Introduced in ES2015 (ES6), the rest parameter is a robust feature in JavaScript that greatly enhances the adaptability of handling function parameters. It allows functions to accept a variable number of arguments, neatly bundled within an array, regardless of the function’s initial structure. The syntax employs three dots (…) before the parameter name, presenting a more dynamic and flexible approach to managing function parameters.

Here’s an explanation and a few examples :

Function Parameters

Example 1:

function add(a, b) { return a + b; }
console.log(add(1, 2));

// Output: 3

console.log(add(1, 2, 3, 4, 5)); // Output: 3

In the first example, passing more arguments than parameters doesn’t throw an error, but only the first two arguments are considered. This behavior changes when using the rest parameter.

Example 2:

function sum(...numbers) {
let total = 0;

for (let num of numbers) {
total += num; }
return total;
}

console.log(sum(1, 2)); // Output: 3

console.log(sum(1, 2, 3)); // Output: 6

console.log(sum(1, 2, 3, 4, 5)); // Output: 15

In the second example, the rest parameter (…numbers) gathers all provided arguments, consolidating them into an array. This enables us to iterate through the array and compute their cumulative sum.

Rest Parameter with Other Parameters

Example 3:

function printDetails(firstName, lastName, ...otherDetails) {
console.log(${firstName} ${lastName}); // Mukul Latiyan

console.log(otherDetails); // [ 'Lionel', 'Messi', 'Barcelona' ] 
console.log(otherDetails[0]); // Lionel 
console.log(otherDetails.length); // 3 
console.log(otherDetails.indexOf('Lionel')); //0
}

printDetails('Mukul', 'Latiyan', 'Lionel', 'Messi', 'Barcelona');

Within this illustration, the rest parameter (…otherDetails) assembles any extra arguments beyond the initial two. Upon utilization, the rest parameter generates an array (otherDetails) amenable to manipulation using array methods. It’s imperative to highlight that the rest parameter should occupy the final position in the parameter list, as its role is to gather any outstanding arguments into an array. Any attempt to position it elsewhere will lead to an error. This rest parameter offers a concise and efficient method for handling diverse quantities of function arguments.

Difference between Rest and Spread operator

FeatureRest Operator (…)Spread Operator (…)
SyntaxGather the remaining function parameters into an array.Spreads elements of an array or object into separate variables or properties.
Function ParametersUsed in function parameters to collect extra arguments.Not applicable in function parameters.
Array DestructuringCollects remaining elements into a designated array.Spreads elements of an array into distinct variables.
Object UsageNot the primary choice for object operations.Spreads properties from one object into another.
Examplejavascript function example(…args) {
// Rest Operator
// Code using args array
}
javascript const arr1 = [1, 2, 3];
const arr2 = […arr1, 4, 5]; // Spread Operator
Use CasesEffective for handling variable function parameters with an unknown number of arguments.Useful for creating array copies, merging arrays, or spreading object properties.
Position in SyntaxFound in the function parameter list to aggregate additional arguments.Placed before an iterable (array or object) to disseminate its elements.
Iteration ApproachTypically used with iteration for processing the collected elements.Spreads elements without iteration, copying them individually.

Join our Best MERN Stack Course program and become an expert in web development career. This Course is for beginners who want to learn web development from the Basics. We cover all the aspects of web development of Web development. This Course is fully packed with amazing content.

Connect with our community

Want to upgrade your skills?

Join Dreamer Infotech and learn from industry expert with live projects and proper guidence

Need Consultation?

AGGREGATE FUNCTIONS
  • MySQL count()
  • MySQL sum()
  • MySQL avg()
  • MySQL min()
  • MySQL max()
MYSQL JOIN

MySQL JOIN

DATA ANALYTICS

DATA PRE-PROCESSING/WRANGLING

NUMPY
  • Fundamentals of NumPy
  • Types of arrays in NumPy
        Ones
        Empty
        Zeros
        Create Random Array
  • Reshaping of the array
         1-D to 2-D array
         2-D to 3-D array
         3-D to 1-D array
  • Arithmetic operations on  Array
         Addition
         Subtraction
         Multiplication
         Exponential
  • Slicing of the array
        How to slice array
        Change in properties during slicing
  • Transpose of a matrix
        How to take transpose
        Rows and columns  while taking transpose
  • Dot product of the matrix
       How to take Dot product of the Matrix
PANDAS
  • Data Frame
         What is Pandas Dataframe
         Different ways to create a Dataframe
        Read data from different sources and convert them to the Dataframe.
  • Pandas Series
        What is panda Series
        How to create a Panda Series.
  • Data inspection
         Using Count, info, head, tail.
         Using Shape, describe, unique, value etc
  • Data Slicing
        Data Slicing loc and iloc
  • Dataframe operations
         How to create a column or row
        How to delete a column or row
    Operations on Rows and Columns
  • Arithmetic operations on rows and
    columns
  • Handle Duplicate value and Null value
  • Handle outlier data
  • Group by Operations
  • Data Reshaping
  • Merging, Joining ,concatenation and
    append
  • Time series
MATPLOTLIB
  • Matplotlib for 3-D visualization
  • Bar, Pie, line, histogram
  • Countplot, boxplot, heatmap
SCIKIT-LEARN
  • Scikit models
  • Preprocessing using Scikit learn
  • Classification using Scikit-learn
  • Clustering using Scikit-learn
  • Regression using Scikit-learn
STATISTICS
  • Scalar and vector
  • Introduction to linear algebra
  • Measure of central tendency mean
  • Measure of central tendency mode
  • Measure of central tendency mode
  • Variance
  • Standard deviation
    Measure of shape skewness
    Measure of shape kurtosis
    Covariance and correlation
PROBABILITY
  • Importance of probability
  • Discrete and continuous variable
  • Bayes Theorem
  • Central Limit theorem
  • Normal Distribution
  • Bernoulli distribution
  • Uniform Distribution
HYPOTHESIS TESTING
  • Hypothesis testing and mechanism
  • Confidence interval
  • Margin of Errors
  • Confidence levels
  • T test and P values using python
  • Z test and P values using python
  • Chi Squared Distribution using python
LINEAR REGRESSION
  • Types of variables
  • Types of Linear variables
  • Mathematics Behind it
  • Implementation of the model
  • Testing and Check
  • Performance of the model
  • Assumptions of the Linear Regression
POLYNOMIAL REGRESSION
  • Need of polynomial Regression
  • Types of Variables in the Polynomial regression
  • Mathematics behind it
  • Implementation of the model
  • Testing and check performance of the
    model
MULTIPLE REGRESSION
  • Need of multiple Regression
  • Mathematics behind it
  • Implementation of the model
  • Testing and check performance of the model
RANDOM FOREST ALGORITHM
  • Why to use random Forest
  • Assumptions in random Forest
  • Working and Implementation of the Model
  • Data Pre-processing in Random Forest
SUPPORT VECTOR MACHINES
  • Types of SVM
  • Implementation of the SVM
  • Creating confusion matrix
NAIVE BAYES CLASSIFIER ALGORITHM
  • Bayes Theoram
  • Implementation of Naïve Bayes
    Classifier
  • Type of Naïve Bayes Model

Need Consultation?

JAVASCRIPT EVENTS

Event listeners and handlers
Mouse events
Keyboard events

DOCUMENT OBJECT MODEL (DOM)

Accessing and manipulating HTML elements
DOM navigation and manipulation
Creating and removing HTML elements

1. INTRODUCTION TO REACT.JS

What is React.js?
History and evolution of React.js
React.js components and their role in
building web applications
Setting up the development environment

JSX

Introduction to JSX
Basic syntax and rules of JSX
Embedding expressions in JSX
Conditional rendering in JSX
Working with lists in JSX

REACT COMPONENTS

Understanding components
Creating class components
Creating functional components
Props and state in React components
Lifecycle methods in React components

REACT EVENTS

Handling events in React
Binding event handlers in React
Passing data to event handlers in React
Conditional rendering based on events in
React

REACT FORMS

Creating forms in React
Handling form submission in React
Controlled and uncontrolled components
in React

REACT ROUTING

Introduction to React Router
Setting up routing in React
Creating routes in React

INTRODUCTION TO MONGODB

What is MongoDB?
Advantages of MongoDB over RDBMS
MongoDB data model and architecture
Setting up the development environment

CRUD OPERATIONS

Creating and inserting documents in
MongoDB
Reading documents from MongoDB
Updating documents in MongoDB
Deleting documents from MongoDB

QUERYING MONGODB

Querying MongoDB using find() method
Querying MongoDB using comparison and
logical operators
Querying MongoDB using regular
expressions
Querying MongoDB using aggregation
framework

INTRODUCTION TO NODE.JS

What is Node.js?
Advantages of Node.js over other serverside technologies
Node.js architecture and event-driven
programming model
Setting up the development environment

NODE.JS MODULES

Introduction to Node.js modules
Creating and using built-in modules
Creating and using custom modules
Working with NPM (Node Package
Manager)

NODE.JS HTTP

Creating HTTP server in Node.js
Understanding HTTP methods and status
codes
Handling HTTP requests and responses
Serving static files in Node.js

EXPRESS.JS FRAMEWORK

Introduction to Express.js framework
Creating and configuring Express.js
application
Handling HTTP requests and responses in
Express.js
Implementing middleware in Express.js

NODE.JS DATABASE CONNECTIVITY

Introduction to database connectivity in
Node.js
Connecting to MongoDB database in
Node.js
Performing CRUD operations in Node.js
using MongoDB
Using Mongoose ORM with MongoDB in
Node.js

NODE.JS SECURITY

Introduction to security in Node.js
Understanding and implementing
authentication and authorization in
Node.js
Implementing HTTPS in Node.js
Preventing common security vulnerabilities
in Node.js

L11
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.

L11
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
change
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.

l12
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
Tab Title
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.
How will I receive my certificate?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Optio, neque qui velit. Magni dolorum quidem ipsam eligendi, totam, facilis laudantium cum accusamus ullam voluptatibus commodi numquam, error, est. Ea, consequatur.

×
Dreamer Infotech - Digital Marketing Course, Data Analyst, Mern Stack Course In Faridabad,Educational Consultant,Faridabad,Haryana