Wednesday, 27 June 2018

Reading Javascript #1

Variable & array


[ 'item 1', 'item 2', 'item 3' ] ← this is array item is value

var ← this refering to variable

var todos ← this is the name of variable

var todos = [ 'item 1', 'item 2', 'item 3' ] ← this complete variable how it should look like.

variable contain name and array. Array is a data

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

console.log


console.log('hello there') ← this is console.log, it show the text print
console.log('hello there', 'muhaza')  ← this is how to combine 2 text

'string' 'value' inside of this '' can be describe as string or value.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

Combine Variable with Console.log


var todos = [ 'item 1', 'item 2', 'item 3' ] ← declare var first
console.log(todos) ← call it by using console.log

Declare and Call terms for my personal note

Variable named todos declared  as [ 'item 1', 'item 2', 'item 3' ] values now its complete as data


-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

to print as text or variable 


console.log(todos) ← this will print as variable

console.log('buat') ← this will be print as text

console.log('buat', todos) ← this will be print text and variable

'buat' is text value, todos is var name that have array with variable data.

-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------


Problem :  Now its already declare var todos have 3 array item. How to add more?

-------------------------------------------------------------------------------------------------------


.push to add more array on declared var


todos.push('item 4') ← add .push after array name and set new array

using () not using []


-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------


Problem :  I have added array item and i want to delete it..

-------------------------------------------------------------------------------------------------------

1. should notice which item inside array you want to delete?
2. you should know that computer start counting from 0

todos[0] ← call the var name and using [] call first item inside array.
todos[1] ← call the var name and using [] call second item inside array.

todos[0] = 'item change' ←  add = and declare new item or value

Result gonna be by type todos on console

before

["item 1", "item 2", "item 3", "item 4"] 

after

["item change", "item 2", "item 3", "item 4"] 



-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...