• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/26

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

26 Cards in this Set

  • Front
  • Back
DEFINE A FUNCTION
var numbers = function(numA, numB) {
var numTotal = numA + numB;
console.log(numTotal); // prints 14 to console
};

numbers(4, 10);

//
ITERATE OVER AN ARRAY
var myArray = ["one", "two", "three", "four"];

for ( var i = 0; i < myArray.length; i++) {

console.log(myArray[i]);

}

//returns array in order
Looping from 10-1
Looping from 10-1:
for(var i = 10; i > 0; i--){
console.log(i);
};

//prints 10 through 1 on the console
Skeleton of an if statement:
var numInput = function (numInput) {

if(numInput === 5) {
console.log("This worked: " + numInput);
}
else if(numInput === 7) {
console.log("This also worked: " + numInput);
}
else {
console.log("The ELSE statement);
}
};


numInput(5);
numInput(7);
numInput(10);
ACCESS FOR ARRAY AND OBJECTS
var myArray = [];
myArray.push(31);
myArray; // myArray now looks like this => [31]
myArray.push('nope');
myArray; // myArray now looks like this => [1, 'nope']

var myObj = {};
myObj['peter'] = '860 park drive';
myObj; // myObj now looks like this => {'peter':'860 park drive'}
var tempVariable = 'marcus';
myObj[tempVariable] = '944 Market';
myObj; // myObj now looks like this => {'tony':'944Market','marcus':'944 Market'}
ARRAY - join()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();

//energy result = Banana,Orange,Apple,Mango

DEFINITION
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 comma (,).
ARRAY - length()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.length;

//result = 4

DEFINITION
The length property sets or returns the number of elements in an array.
ARRAY - pop()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();

//fruits result = Banana,Orange,Apple

DEFINITION
The pop() method removes the last element of an array, and returns that element.

Note: This method changes the length of an array.

Tip: To remove the first element of an array, use the shift() method.
ARRAY - push()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi")

//fruits result = Banana,Orange,Apple,Mango,Kiwi

DEFINITION
The push() method adds new items to the end of an array, and returns the new length.

Note: The new item(s) will be added at the end of the array.

Note: This method changes the length of the array.

Tip: To add items at the beginning of an array, use the unshift() method.
ARRAY - reverse()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.reverse();

//fruits result = Mango,Apple,Orange,Banana

DEFINITION
The reverse() method reverses the order of the elements in an array.
ARRAY - shift()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift()

//fruits result = Orange,Apple,Mango

DEFINITION
The shift() method removes the first item of an array, and returns that item.

Note: This method changes the length of an array!

Tip: To remove the last item of an array, use the pop() method.
ARRAY - unshift()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");

//fruits result = Lemon,Pineapple,Banana,Orange,Apple,Mango

DEFINITION
The unshift() method adds new items to the beginning of an array, and returns the new length.

Note: This method changes the length of an array.

Tip: To add new items at the end of an array, use the push() method.
ARRAY - slice()
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1,3);

//fruits result = Orange,Lemon

DEFINITION
The slice() method returns the selected elements in an array, as a new array object.

The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.
ARRAY - splice()
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,0,"Lemon","Kiwi");

//fruits result = Banana,Orange,Lemon,Kiwi,Apple,Mango

DEFINITION
The splice() method adds/removes items to/from an array, and returns the removed item(s).

Note: This method changes the original array.
ARRAY - Object.keys(yourObjectHere)
Returns an array of a given object's own enumerable properties, in the same order as that provided by a for-in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
STRINGS - charAt()
var str = "HELLO WORLD";
var res = str.charAt(0)

//res result = H

DEFINITION
The charAt() method returns the character at the specified index in a string.

The index of the first character is 0, the second character is 1, and so on.

The index of the last character is -1, the second last character is -2, and so on.
STRINGS - concat()
var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);

//result of res = Hello world!

DEFINITION
The concat() method is used to join two or more strings.

This method does not change the existing strings, but returns a new string containing the text of the joined strings.
STRINGS - indexOf()
var str = "Hello world, welcome to the universe.";
var n = str.indexOf("welcome");

//result of n = 13

DEFINITION
The indexOf() method returns the position of the first occurrence of a specified value in a string.

This method returns -1 if the value to search for never occurs.

Note: The indexOf() method is case sensitive.
STRINGS - length()
var str = "Hello World!";
var n = str.length;

//result of n = 12

DEFINITION
The length property returns the length of a string (number of characters).

The length of an empty string is 0.
STRINGS - search()
var str = "Visit W3Schools!";
var n = str.search("W3Schools");

//result of n = 6

DEFINITION
The search() method searches a string for a specified value, or regular expression, and returns the position of the match.

This method returns -1 if no match is found.
STRINGS - slice()
var str = "Hello world!";
var res = str.slice(1,5);

//result of res = "ello"

DEFINITION
The slice() method extract parts of a string and returns the extracted parts in a new string.

Use the start and end parameters to specify the part of the string you want to extract.

The first character has the position 0, the second has position 1, and so on.

Tip: Use a negative number to select from the end of the string.
STRINGS - split()
var str = "How are you doing today?";
var res = str.split(" ");

//results of res (as an array) = How,are,you,doing,today?

DEFINITION
The split() method is used to split a string into an array of substrings, and returns the new array.

Tip: If an empty string ("") is used as the separator, the string is split between each character.

Note: The split() method does not change the original string.
STRINGS - sub()
var str = "Hello World!";
var result = str.sub();

DEFINITION
The sub() method is not standard, and may not work as expected in all browsers.

The sub() method is used to display a string as subscript text.

This method returns the string embedded in the <sub> tag, like this:

<sub>string</sub>
STRINGS - substr()
var str = "Hello world!";
var res = str.substr(1,4)

//result of res = ello

DEFINITION
The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

Tip: To extract characters from the end of the string, use a negative start number (This does not work in IE 8 and earlier).

Note: The substr() method does not change the original string.
STRINGS - toLowerCase()
var str = "Hello World!";
var res = str.toLowerCase();

//results of res = hello world!

DEFINITION
The toLowerCase() method converts a string to lowercase letters.

Note: The toLowerCase() method does not change the original string.
STRINGS - toUpperCase()
var str = "Hello World!";
var res = str.toUpperCase();

//results of res = HELLO WORLD!

DEFINITION
The toUpperCase() method converts a string to uppercase letters.

Note: The toUpperCase() method does not change the original string.