DEV Community

Cover image for Top Javascript Cheat sheet
Kamran Ahmad
Kamran Ahmad

Posted on

Top Javascript Cheat sheet

1.String Methods
string.includes('subtring')
checks whether a substring exists inside of a string
[check the character case]

string.indexOf(searchValue)
returns the index of the first occurrence of the
specified value, starting the search at fromIndex.
Returns -1 if the value is not found.

string.lastIndexOf(searchValue)
returns the index of the last occurrence of the
specified value, searching backwards from
fromIndex. Returns -1 if the value is not found.

string.slice(beginIndex, endIndex)
extracts a section of a string and returns it as a new
string, without modifying the original string.

  1. Array Methods

array[index]
returns a certain value from an array

push(value)
adds the value to the end of the array

pop()
removes the value from the end of the array

shift()
removes the value from the start of the array

unshift(value)
adds the value to the start of the array

splice(fromIndex, no_of_elements)
removes the number_of_elements, starting from
fromIndex from the array

slice(fromIndex, toIndex)
copies a certain part of the array

concat()
Join several arrays into one

join('')
returns a string of array values

array.length
returns the number of elements in the array

reverse()
reverse the order of the elements in an array

toString()
returns a string representing the specified array
and its elements.

3.Date Objects
getUTCMinutes()
Same as getMinutes(), but returns the UTC minutes

getUTCSeconds()
Same as getSeconds(), but returns the UTC seconds

getUTCMilliseconds()
Same as getMilliseconds(), but returns the UTC
milliseconds

  1. Window Object Properties sessionStorage Allows to save key/value pairs in a web browser.

Stores the data for one session
scrollX
An alias of pageXOffset

scrollY
An alias of pageYOffset

status
Sets or returns the text in the statusbar of a window

top
Returns the topmost browser window

Top comments (2)

 
camco profile image
Camco

I agree.

I'm not sure of the intent, but the quality of the post is sub par in my opinion. I don't know if I would go as far to say "useless", I would say there are much more useful posts than this. 😎

Collapse
 
briang123 profile image
Brian Gaines

Wow, ya don’t need to be a douche about it.