What’s the use of the method in JavaScript?

method in JavaScript

  • Concat ( ) Method
  • Join ( ) Method
  • Reverse ( ) Method
  • Slice( ) Method
  • Splice ( ) Method
  • toString( ) Method
  • Array.isArray ( ) Method
  • IndexOf ( ) Method
  • Fill ( ) Method
  • unshift ( ) Method
  • Shift( ) Method
  • Shift( ) Method
  • pop( ) Method
  • Map ( ) Method

Concat ( ) Method

The concat() method is used to merge two or more arrays. This method does not change
the existing arrays, but instead returns a new array.

Syntax:- new_array = old_array.concat(value1, value2, value_n);
Syntax:- new_array = old_array1.concat(old_array2, old_array_n);

Join ( ) Method

The join() method joins the elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is the comma (,).

Syntax: – array_name.join(separator);

Reverse ( ) Method

The reverse() method reverses the order of the elements in an array.

Syntax :- array_name.reverse( );

Ex:- dev.reverse( );

Slice( ) Method

The slice( ) method returns a shallow copy of a portion of an array into a new array object selected from beginning to
end (end not included). The original array will not be modified.

Syntax: – array_name.slice(start, end)

Start
If begin is undefined, the slice begins from index 0.
If begin is greater than the length of the sequence, an empty array is returned.
A negative index can be used, indicating an offset from the end of the sequence. slice(-2) extracts the last two
elements in the sequence.

End
If end is omitted, slice extracts through the end of the sequence (arr.length).
If end is greater than the length of the sequence, slice extracts through to the end of the sequence (arr.length).
A negative index can be used, indicating an offset from the end of the sequence. slice(2,-1) extracts the third
element through the second-to-last element in the sequence.
slice extracts up to but not including end.

Splice ( ) Method

The splice() method changes the contents of an array by removing existing elements and/or adding new elements. This method changes the original array.

Syntax:- array_name.splice (start, deletecount, replacevalues);

Start – The first argument start specifies at what position to add/remove items, uses negative values to specify the position from the end of the array.

Deletecount – The second argument deletecount, is the number of elements to delete
beginning with index start.

Replacevalues – replacevalues are inserted in the place of the deleted elements. If more
than one separate it by a comma.

toString( ) Method

The toString ( ) method returns a string containing the comma-separated values of the array. This method is invoked automatically when you print an array. It is equivalent to invoking the join ( ) method without any arguments. The
the returned string will separate the elements in the array with commas.

Syntax: – array_name.toString();

Array.isArray ( ) Method

The Array.isArray() method determines whether the passed value is an Array. This function returns true if the object is an array, and false if not.

Syntax:- Array.isArray(value);

IndexOf ( ) Method

This method allows us to easily find the occurrence of an item in an array.

  • If the item is not found, it returns -1.
  • The search will start at the specified position, or at the beginning if no start position is specified, and end the search at the end of the array.
  • If the item is present more than once, the indexOf method returns the position of the first occurrence.

Syntax: – var position = array_name.indexOf(item, start);

Ex:- var position = dev.indexOf(“Rohit”, 2);

Fill ( ) Method

The fill() method fills all the elements in an array with a static value.

Syntax:- array_name.fill(value, start, end)

unshift ( ) Method

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
This method changes the length of an array.

Syntax: –
Array_name.unshift(value1, value2, value_n);

Push ( ) Method

The push() method adds one or more elements to the end of an array and returns the new length of the array.
The new item will be added at the end of the array.
This method changes the length of the array.

Syntax: –
Array_name.push(value1, value2, value_n);

Shift( ) Method

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

Syntax: – array_name.shift( );

Ex: – geek.shift( );

pop( ) Method

The pop() method removes the last element from an array and returns that removed element. This method changes the length of the array.

Syntax: – array_name.pop( );

Ex: – geek.pop( );

Map ( ) Method

The map() method creates a new array with the results of calling a provided function on every element in the calling array.
The map() method calls the provided function once for each element in an array, in order.

map() does not execute the function for array elements without values.
map() does not change the original array.

Syntax:- array_name.map(function(currentValue, index, array)
{
}, thisValue

Tagged : / / / /

30 Most Popular Regular expression Tricks in Visual Studio Code

Although almost all text editors now support regular expressions, I use Visual Studio Code for an easy way to know.

You need to enable RegEx by selecting this option. (.*)

PurposeExpressionExample
Match any single character (except a line break). For more information, see Any character..a.o matches “aro” in “around” and “abo” in “about” but not “acro” in “across”
Match zero or more occurrences of the preceding expression (match as many characters as possible). For more information, see Match zero or more times.*a*r matches “r” in “rack”, “ar” in “ark”, and “aar” in “aardvark”
Match any character zero or more times..*c.*e matches “cke” in “racket”, “come” in “comment”, and “code” in “code”
Match one or more occurrences of the preceding expression (match as many characters as possible). For more information, see Match one or more times.+e+d matches “eed” in “feeder” and “ed” in “faded”
Match any character one or more times..+e.+e matches “eede” in “feeder” but finds no matches in “feed”
Match zero or more occurrences of the preceding expression (match as few characters as possible). For more information, see Match zero or more times (lazy match).*?\w*?d matches “fad” and “ed” in “faded” but not the entire word “faded” due to the lazy match
Match one or more occurrences of the preceding expression (match as few characters as possible). For more information, see Match one or more times (lazy match).+?e\w+? matches “ee” in “asleep” and “ed” in “faded” but finds no matches in “fade”
Anchor the match string to the beginning of a line or string^^car matches the word “car” only when it appears at the beginning of a line
Anchor the match string to the end of a line\r?$car\r?$ matches “car” only when it appears at the end of a line
Anchor the match string to the end of the file$car$ matches “car” only when it appears at the end of the file
Match any single character in a set[abc]b[abc] matches “ba”, “bb”, and “bc”
Match any character in a range of characters[a-f]be[n-t] matches “bet” in “between”, “ben” in “beneath”, and “bes” in “beside”, but finds no matches in “below”
Capture and implicitly number the expression contained within parenthesis()([a-z])X\1 matches “aXa”and “bXb”, but not “aXb”. “\1” refers to the first expression group “[a-z]”.
Invalidate a match(?!abc)real(?!ity) matches “real” in “realty” and “really” but not in “reality.” It also finds the second “real” (but not the first “real”) in “realityreal”.
Match any character that is not in a given set of characters. [^abc]be[^n-t] matches “bef” in “before”, “beh” in “behind”, and “bel” in “below”, but finds no matches in “beneath”
Match either the expression before or the one after the symbol|(sponge|mud) bath matches “sponge bath” and “mud bath”
Escape the character following the backslash\\^ matches the character ^
Specify the number of occurrences of the preceding character or group.{n}, where ‘n’ is the number of occurrencesx(ab){2}x  that matches “xababx”
x(ab){2,3}x matches “xababx” and “xabababx” but not “xababababx”
Match text in a Unicode category.\p{X}, where “X” is the Unicode number.\p{Lu} matches “T” and “D” in “Thomas Doe”
Match a word boundary\b (Outside a character class \b specifies a word boundary, and inside a character class \b specifies a backspace.)\bin matches “in” in “inside” but finds no matches in “pinto”
Match a line break (that is, a carriage return followed by a newline)\r?\nEnd\r?\nBegin matches “End” and “Begin” only when “End” is the last string in a line and “Begin” is the first string in the next line
Match any word character\wa\wd matches “add” and “a1d” but not “a d”
Match any whitespace character\sPublic\sInterface matches the phrase “Public Interface”
Match any decimal digit character\d\d matches “4” and “0” in “wd40”
Decimal digit character\(?\(? Match zero or one literal “(” character.
Decimal digit character[\s-][\s-] Match a hyphen or a white-space character.
Decimal digit character(\(?\d{3}\)?[\s-])?(\(?\d{3}\)?[\s-])? Match an optional opening parenthesis followed by three decimal digits, an optional closing parenthesis, and either a white-space character or a hyphen zero or one time. This is the first capturing group.
Decimal digit character\d{3}-\d{4}\d{3}-\d{4} Match three decimal digits followed by a hyphen and four more decimal digits.
Whitespace character\x85\x85 The ellipsis or NEXT LINE (NEL) character (…), \u0085.
Whitespace character\p{Z}\p{Z} Matches any separator character.
Tagged : / / / / /

HTML: Audio Tag

The <audio>… </audio> tag defines sound, such as music or other audio streams.

Supported Format: mp3, wav, and ogg

AttributeValueDescription
autoplayautoplaySpecifies that the audio will start playing as soon as it is ready
controlscontrolsSpecifies that audio controls should be displayed (such as a play/pause button etc)
looploopSpecifies that the audio will start over again, every time it is finished
mutedmutedSpecifies that the audio output should be muted
preloadauto
metadata
none
Specifies if and how the author thinks the audio should be loaded when the page loads
srcURLSpecifies the URL of the audio file

preload

Tagged : / / /

HTML: Map tag

The <map>….</map> tag is used to define a client-side image-map. An image-map is an image with clickable areas.

The <map>…. </map> tag contains a number of <area> tags, that defines the clickable areas in the image map.

<map name=“mapname” id=“mapname”>……… </map>

Area Tag

The <area> tag defines an area inside an image-map. An image-map is an image with clickable areas.

The <area> element is always nested inside a <map>….</map> tag.

AttributeValueDescription
alttextSpecifies an alternate text for the area. Required if the href attribute is present
coordscoordinatesSpecifies the coordinates of the area
downloadfilenameSpecifies that the target will be downloaded when a user clicks on the hyperlink
hrefURLSpecifies the hyperlink target for the area
hreflanglanguage_codeSpecifies the language of the target URL
mediamedia querySpecifies what media/device the target URL is optimized for
shapedefault
rect
circle
poly
Specifies the shape of the area
target_blank
_parent
_self
_top
framename
Specifies where to open the target URL
typemedia_typeSpecifies the media type of the target URL
relalternate
author
bookmark
help
license
next
nofollow
noreferrer
prefetch
prev
search
tag
Specifies the relationship between the current document and the target URL

Coords attribute:

Tagged : / / / /

HTML: Image tag

The <img> tag is used to insert images on web pages.

AttributeValueDescription
srcURLSpecifies the URL of an image
alttextSpecifies an alternate text for an image
widthpixelsSpecifies the width of an image
heightpixelsSpecifies the height of an image
ismapismapSpecifies an image as a server-side image-map
usemap#mapnameSpecifies an image as a client-side image-map

src attribute

<img src=“car.jpg”>
<img src=“C:\image\dog.jpg”>

alt attribute

<img src=“car.jpg” alt=“car”>

// If the image is not to be open then its attribute message show in alt=”car”.

Width and height attribute

<img src=“car.jpg” alt=“car” width=“200” height=“100”>

ismap attribute

click coordinates are sent to the server.

Tagged : / / / / / / / / /