function StringCheck(string){
const arr = string.split('')
const result = arr.fill("*", 1,5)
return result.join('')
}
StringCheck("0123456")
// result: '0****56'
("asdf", 1,5)
function cb(element) {
// return (element[0] === '์กฐ')
return element.startsWith("์กฐ")
//์ด๊ฑธ ์ฝ์๋ก ์ฐ์ด๋ณด๋ฉด false, false, true, false ๊ฐ ๋ธ
}
const result = arr.findIndex(cb); //๊ทธ๋ ๊ฒ ๋ฌ boolean ๊ฐ์ index num์ ์ฐพ์๋ด๋๊ฒ ๋ชฉํ
console.log(result); // 2
function solution(front, back) {
return front.filter( el => back.includes(el))
// back์๋ ํฌํจ๋์ด์๋ element๋ง ๊ณจ๋ผ์ ์ถ๋ ฅ
}
(element => element.legnth < 5)
: ์ซ์, ๋ฌธ์์ด, ๋ฐฐ์ด, ๊ฐ์ฒด ๋ฑ ๋ชจ๋ ๋ฐ์ดํฐ ์์ฉ ๊ฐ๋ฅ
const fruits = [];
fruits.push('์ฌ๊ณผ', "๋ฐ๋๋",'ํ์ธ์ ํ')
// push๋ push ๋ ์ดํ์ ๊ธธ์ด๊ฐ์ ๋ฆฌํดํจ ๊ทธ๋์ ๋ง์ฝ์
// const newFruits = fruits.push('์ฌ๊ณผ', "๋ฐ๋๋",'ํ์ธ์ ํ')
// ์ผ๋ก ํ๋ค๋ฉด push๋ ๊ฒฐ๊ณผ๋ 3์ด ๋์ค๊ฒ ๋๋๊ฑฐ์
// push๋ ์๋ณธ๊ฐ ์์ฒด๋ฅผ ์์ ํ๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก ๋ณ์๋ฅผ ์ ์ธํด์ ๋ด์์ฃผ์ง ์์๋ ๋จ
fruits
// =========== All at once ===========
const secondFruits = ['์ฌ๊ณผ','๋ฐ๋๋','ํ์ธ์ ํ']
console.log(secondFruits)
// ๋ฐฐ์ด์ ๋ง์ง๋ง ๋ฐ์ดํ ๊ฐ์ ธ์์ ์ ๋ฐฐ์ด์ ๋ด์์ฃผ๊ธฐ
const fruits = ['์ฌ๊ณผ','๋ฐ๋๋','ํ์ธ์ ํ']
fruits[0] //'์ฌ๊ณผ'
fruits[1] //'๋ฐ๋๋'
fruits[2] //'ํ์ธ์ ํ'
const newFruits = fruits[fruits.length-1]
newFruits
: ๋ฐ์ดํฐ๋ค์ ์ข ๋ฅ์ ๋ง๊ฒ ๋ถ๋ฅํ์ฌ ์ ์ฅ
const Obj = {
"name":"JB",
"age":18,
"hobby": {
"ball":"volley ball",
"water":"swim"
}
}
Obj.name // result: 'JB' //key๊ฐ์ ์ด๋ฆ์ ์ ํํ ์
๋ ฅํด์ผํจ
Obj["name"] // result: 'JB'
Obj.age // result: 18
Obj["age"] //result: 18
let a = "age"
Obj[a] // result: 18 //key๊ฐ์ ์ด๋ฆ์ ๊ฐ์ง๊ณ ์๋ ๋ณ์๋ฅผ ํ ๋นํ ์ ์์
Obj.dog = "์์ด"
// result:
const Obj = {
"name":"JB",
"age":18,
"hobby": {
"ball":"volley ball",
"water":"swim"
}
"dog":"์์ด" // ์กด์ฌํ๋ key๊ฐ์ด ์๋ค๋ฉด ์๋ก ์ถ๊ฐํ๊ณ ๋ง์ฝ ์ด๋ฏธ ์กด์ฌํ๋ key๊ฐ์ด ์๋ค๋ฉด ๋ณ๊ฒฝ์ด ๋๋๊ฑฐ์
}
์ฌ๊ธฐ์ ๋ง์ฝ Obj.dog = "๊ฐ์ฅ"
๋ฅผ ํ๋ค๋ฉด
// result:
const Obj = {
"name":"JB",
"age":18,
"hobby": {
"ball":"volley ball",
"water":"swim"
}
"dog":"๊ฐ์ฅ"
}
delete Obj.dog
// result:
const Obj = {
"name":"JB",
"age":18,
"hobby": {
"ball":"volley ball",
"water":"Swim"
}
}
Obj.hobby.art = "architecture"
delete Obj.hobby.water
//result:
const Obj = {
"name":"JB",
"age":18,
"hobby": {
"ball":"volley ball",
"art":"architecture"
}
}
const student = {}
student.name = "JB"
student
// resut: { name: 'JB' }
const student = {
name:"aba",
age: 8
}
const school = {
name: "aaa",
teacher: "aa"
}
student["school"] = school //ํ ๋น
//or student.school = school
console.log(student) //์ฐ์ด๋ด๊ธฐ
// result:
// {
// name: 'aba',
// age: 8,
// school: { name: 'aaa', teacher: 'aa' }
// }