SheTech
  • SheTech JS bootcamp
  • Level 1 - awesome tasks
    • Introduction to Awesome Tasks
    • Step 1: HTML
    • Step 2: playing with the DOM
    • Step 3: add a new task
    • Step 4: dynamic list of tasks
    • Step 5: adding new items
    • Step 6: removing items
    • Step 7: add some style
    • Step 8: marking items as done
    • Step 9: saving items in the localstorage
    • Step 10: adding filters and bulk actions
    • Step 11: add counters
    • From Awesome Task to the next big thing!
  • Level 2 - timeline
    • Live Timeline
    • Step 1: basic HTML page
    • Step 2: add util library
    • Step 3: show all posts
    • Step 4: add form
    • Step 5: collect form data
    • Step 6: create a new post
    • Step 7: validating posts
    • Step 8: refactoring
    • Step 9: refresh button
    • Step 10: auto refresh
  • Code Editors
  • Useful resources
  • API Reference
  • Glossary
Powered by GitBook
On this page
  • Array
  • .filter(callback) (see in MDN)
  • .forEach(callback) (see in MDN)
  • .push(element) (see in MDN)
  • Event
  • .target (see in MDN)
  • .preventDefault() (see in MDN)
  • String
  • .replace(pattern, replacement) (see in MDN)
  • .trim() (see in MDN)
  • JSON
  • .parse(jsonString) (see in MDN)
  • .stringify(object) (see in MDN)
  • document
  • .querySelector(cssSelector) (see in MDN)
  • Element
  • .innerHTML (see in MDN)
  • .previousElementSibling (see in MDN)
  • .dataset (see in MDN)
  • .value (see in MDN)
  • console
  • .log(text) (see in MDN)

Was this helpful?

API Reference

PreviousUseful resourcesNextGlossary

Last updated 4 years ago

Was this helpful?

Array

.filter(callback) ()

Executes a function on every element of the Array. It returns a new Array that contains only the elements for which the provided function returned true.

Example:

var myArray = [5, 6, 1, 2, 10];

var filteredArray = myArray.filter(function(num) {
    return num > 3; // Returns true only if the number is greater than 3
});

// filteredArray is [5, 6, 10]

.forEach(callback) ()

Allows to execute a function on each and every element of the Array.

Example:

var myArray = ['Mickey', 'Goofy', 'Donald'];

myArray.forEach(function(name) {
   console.log('Hello' + name);
};

// Console Output
Hello Mickey
Hello Goofy
Hello Donald

Appends an element at the end of the Array.

Example:

var myArray = [20, 100, 30];

myArray.push(50);

// myArray is now [20, 100, 30, 50]

Event

Returns the element on which the event was captured.

Cancels the default event behavior.

String

Returns a copy of the String with the given pattern replaced with another String.

Example:

var myString = 'This and that';

var newString = myString.replace('and', 'or');

// newString is 'This or that'

Returns the original String without the whitespaces that it might have at the beginning or at the end.

Example:

var myString = '    Chocolate  ';

var newString = myString.trim();

// newString is 'Chocolate'

JSON

Converts a JSON string into a Javascript Object.

var myObject = JSON.parse('{"type": "door", "state": "open"}');

// myObject is { type: 'door', state: 'open' }

Converts a Javascript Object into a JSON string.

var myObject = { type: 'door', state: 'open' };
var jsonString = JSON.stringify(myObject);

// jsonString is '{"type":"door","state":"open"}'

document

Returns the first element that matches the provided CSS selector.

Example:

// HTML
<div class="container">
   <div id="myElement">
      <span>Hello!</span>
   </div>
</div>

// Javascript
var myElement = document.querySelector('#myElement');

// myElement contains a reference to <div id="myElement"></div>

Element

Returns the HTML contained inside an Element. It can be set to a new value.

Example:

// HTML
<div id="myElement">
  <span>Hello!</span>
</div>

// Javascript
var myElement = document.querySelector('#myElement');

// myElement.innerHTML returns '<span>Hello!</span>'

myElement.innerHTML = '<div>Something else</div>';

// Now the HTML is this:
<div id="myElement">
  <div>Something else</div>
</div>

Returns the Element before the selected one.

Example:

// HTML
<div class="container">
   <span>One</span>
   <span class="selected">Two</span>
   <span>Three</span>
</div>

// Javascript
var selected = document.querySelector('.selected');
var previous = selected.previousElementSibling;

// previous is <span>One</span>

Returns the map of the data- attributes of the selected element.

Example:

// HTML
<div id="myElement" data-type="door" data-state="open"></div>

// Javascript
var door = document.querySelector('#myElement');
var dataSet = door.dataset;

// dataSet is { type: 'door', state: 'open' }

Returns or sets the value of the input field.

console

Writes a message in the browser's console.

.push(element) ()

.target ()

.preventDefault() ()

.replace(pattern, replacement) ()

.trim() ()

.parse(jsonString) ()

.stringify(object) ()

.querySelector(cssSelector) ()

.innerHTML ()

.previousElementSibling ()

.dataset ()

.value ()

.log(text) ()

see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN
see in MDN