0% found this document useful (0 votes)
28 views

Data Strucutures Modern Operatos and Strings

This document discusses various JavaScript string, array, and object methods. It covers topics like destructuring, spread syntax, optional chaining, sets, maps, and working with strings. Numerous code examples are provided to demonstrate each concept.

Uploaded by

patelsurlko20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Data Strucutures Modern Operatos and Strings

This document discusses various JavaScript string, array, and object methods. It covers topics like destructuring, spread syntax, optional chaining, sets, maps, and working with strings. Numerous code examples are provided to demonstrate each concept.

Uploaded by

patelsurlko20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Index

1.De-
Folder location ⬇️ structuri
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and Strings\Destructuring Arrays

Output of code:

1.2 It stores array values one by one by default


Example:

the output of code:

1.3 If you want to store array value in your order


Example: -

Or you can define function inside object


1.4: Swap

1.5 Nested Array

The output of code:

1.6 If not know how many array elements present in the array

The output of code:


2.De-
structuri
Folder location ⬇️
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Destructuring Objects

The output of code:

2.1: Creating own variable name and assigning object values


The output of code:

2.2: If you don't know whether the object element is present or not

The output of code:

2.3: Mutating variables

The output of code:

2.4 Nested Objects

The output of code:


2.5 If you don't know parameter position then we use obj

The output of code:


3. The
Spread
Folder Location: -
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\The Spread Operator (...)

3.1: If you want to copy all elements of the array in a new array

The output of code:

3.2: If you want to print array values without a loop then use

The output of code:

3.3: Creating array using object array

The output of code:


3.4: Copy array and join 2 or more arrays

The output of code:

3.5: Printing string and adding string in arrays

The output of code:

3.6: You don’t use Spread Operator (…) in object


3.7: passing argument using (...)
The output of code:

3.8: Object copy and creating new object

The output of code:

3.9: Copy object and changing name

The output of code:

4. Rest
Folder Location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Rest Pattern and Parameters

This is part of Destructing


4.1: REST, because on LEFT side of =

The output of code:

the output of code:

4.2: Objects

The output of code:

This is part of Function


The output of code:
You can pass many arguments there is no limit

4.3: Example

The output of code


5. Short
Circuitin
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Short Circuiting (AND and OR)

OR
5.1: Use Any data type, return any data type, short-circuiting

The output of code:

5.2: Easy way to write without using ternary operator

The output of code:

AND
The output of code:

Example:

The output of code:


6. The Nullish Coalescing Operator (??)
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\The Nullish Coalescing Operator

The output of code:


7. Logical Assignment Operators
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Logical Assignment Operators

7.1: Or assignment operator

The output of code:

7.2: Nullish assignment operator

The output of code:


7.3: AND assignment operator

The output of code:


Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Looping Arrays The for-of Loop

8.1: For loop – for- of loop

The output of code:

Using entries()
8.2: If you want to print elements with their index then write like this

The output of code:

8.3: Using DE structuring for printing index+1 and print element


The output of code:
9. Enhanced Object Literals
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Enhanced Object Literals

9.1: If you want include outside object inside a another object

The output of code:


9.2: Inside the object you can also write a function like this

9.3: You can also write object variable like that

The output of code:


10. Optional Chaining (?.)
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Optional Chaining (Question_mark dot)
10.1: Using Optional Chaining

The output of code:

Example:

The output of code:

10.2: Methods
This work only return not console.log else it print both
The output of code:

This work only returns not console.log else it print both Example below

The output of code:


11. Looping Objects (Object Keys, Values, and Entries)

Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\Looping Objects (Object Keys, Values, and Entries)

11.1: Property NAMES

The output of code:

11.2: Property Values

The output of code:

11.3: Entire Object

The output of code:


11.4: Using for loop and printing Key and value both

The output of code:


12. Sets
Folder Location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\12. Sets

Set objects are collections of values. A value in the set may only occur once; it is
unique in the set's collection. You can iterate through the elements of a set in
insertion order. The insertion order corresponds to the order in which each
element was inserted into the set by the add() method successfully (that is, there
wasn't an identical element already in the set when add() was called).
Example:

The output of code:

2. Example

The output of code:

12.1: Finding Size of Sets

The output of code:


12.2: element present on set or not using (has) function

The output of code:

12.3: Adding element in the Set

The output of code:

12.4: Clear Full set or Empty Set

The output of code:

12.5: Iterating using for loop

The output of code:

12.6: Example
The Output of code:

12.7: Converting set into array

The output of code:


Folder Location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\13. Maps Fundamentals

The Map object holds key-value pairs and remembers the original insertion
order of the keys. Any value (both objects and primitive values) may be used as
either a key or a value.
13.1: Creating Map And Adding Value, For adding value we use (set) and you can
also use Int for key

The output of code:

13.2: You can also add Boolean key array or etc

13.3: You can access map values by using get and calling with keys
The output of code:

13.4: Check whether Key available or not in the Map

The output of code:

13.5: If you want to delete a key then use delete keyword

The output of code:

13.6: Deleting Map using clear operator clear()

13.7: Finding the Size of the Map using operator size

The output of code:

13.8.1: Passing array but this gone not work for calling with key Example below
The output of code:

13.8.2: Pass array like that so you can get access

The output of code:

13.9: You can also set the object and etc

The output of code:

14. Map: Iteration


Folder Location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\14. Map Iteration

14.1: Way of creating Map using array

The output of code:

14.2: Convert object to a map

The output of code:

14.3: Iterating Object


The output of code:

14.4: Converting a map to array and getting map value and key

The output of code:

15. Summary: which data structure to use?


16. Working With Strings -
Folder location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\16. Working With Strings - Part 1

16.1: Getting element by index number like array Or You can direct pass string

16.2: Find length of String You can also do with direct pass string

16.3: Find Index number and This is case sensitive

16.4: Find Index of from the last

16.5: Find word position

16.4: slice()
16.4.1: slice method

16.4.2: slice method with begin and end


16.4.3: If you want extract first word without knowing length of first word

16.4.4: If you want extract last word

16.4.5: We can use negative value like in python

17. Working with Strings - Part 2


Folder Location
C:\Users\patel\Desktop\Js\JavaScript\Data Structures, Modern Operators and
Strings\17. Working With Strings - Part 2

17.1: Changing into lowercase and Uppercase

Example: Fix capitalization in name

17.2: Remove spaces with trim():

17.3.1: Replacing: This is replaced only first occurrence

17.3.2: Replacing all occurrence of same word

OR second method
17.4: Checking if the string includes some character or not Using includes()

17.5: The startsWith() method determines whether a string begins with the
characters of a specified string, returning true or false as appropriate.

17.6: The endsWith() method check from last string


18. Working with Strings - Part 3

You might also like