본문 바로가기

JS6

2023-06-13 javascript_string myString.indexof('[형]') It returns the starting index of the parameter. It can find if the whole part is in the string or not. When we copy array/object, and if there is another array/object in the original array or object, then an address of the array/object is copied not values. It means copied array/object which belongs to the original array/object is no more individual array/object. If we wa.. 2023. 6. 13.
2023-05-16 javascript_array let voteCounter = {}; /*let i=0; let j=0;*/ for (let name of votes) { /*if(name==='이재식'){ voteCounter[name]=++i; }else{ voteCounter[name]=++j; }*/ if(name in voteCounter){ voteCounter[name]=voteCounter[name]+1; }else{ voteCounter[name]=1; } } We don't have to define variable i and j, if we use the second codes not the first codes. 2023. 5. 16.
2023-05-13 javascript //delete first element in array members.shift(); //delete last element in array members.pop(); //add element as first element of array members.unshift('Hello'); //add element as last element of array members.push('Bye'); brands.indexOf('Kakao'); Find 'Kakao' in array. If the array has it, then the array returns the index of it. If not, the array returns -1. Moreover, if the array has same multip.. 2023. 5. 13.
2023-05-11 javascript members=[ 'kim', 'choi', 'park' ]; members.splice(1,2); We delete elements of array using splice method. We first put the starting index as a first parameter, and the number of element that we want to delete as a second parameter. Meanwhile, the meaning of splice(1,2) is delete 2 elements from starting index 1. Therefore, only 'kim' will remain after the splice method is executed. members.splice.. 2023. 5. 11.