Open5

JavaScript学習記録3

ミワミワ

section1_配列に複数の値をまとめる

t4_1.js
console.log("つみトレ4章: SECTION_01");
console.log("配列に複数の値をまとめる");

// c4_1_1.js
let walks = ['抜き足','差し脚','忍び足'];
console.log(walks);
walks[1] = '駆け足';
console.log(walks);
t4_1.js
// c4_1_2.js
let ninja = ['佐助','才蔵','六郎'];
let samurai = ['信長','秀吉','家康'];
let people = [ninja,samurai];
console.log(people);

console.log(people[0][0]);
t4_1.js
// c4_1_3.js
let shogun = ['家光','家綱'];
shogun.push('綱吉');
console.log(shogun);

shogun.unshift('秀忠');
console.log(shogun);

let matsudaira = ['家康','健'];
shogun = shogun.concat(matsudaira);
console.log(shogun);

shogun.splice(5,1);
console.log(shogun);

let shodai = shogun.pop();
console.log(shogun);
console.log(shodai);
shogun.unshift(shodai);
console.log(shogun);
ミワミワ

section2_配列を操作する

t4_2.js
console.log("つみトレ4章: SECTION_02");
console.log("配列を操作する");

// c4_2_1.js
let daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
console.log(daysInMonth.length);

console.log(daysInMonth.includes(28));
console.log(daysInMonth.includes(29));
t4_2.js
// c4_2_2.js
let daysInMonth2 = [31,28,31,30,31,30,31,31,30,31,30,31];
console.log(daysInMonth2.lastIndexOf(30));
t4_2.js
// c4_2_3.js
let week1 = ['月','火','水','木','金'].fill('祝');
let week2 = ['月','火','水','木','金'].fill('祝',2);
let week3 = ['月','火','水','木','金'].fill('祝',2,3);
console.log(week1);
console.log(week2);
console.log(week3);
t4_2.js
// c4_2_4.js
let music =['Aメロ', 'サビ'];
console.log(music);
music.splice(1,0,'Bメロ');
console.log(music);
t4_2.js
// c4_2_5.js
let duranDuran=['Simon','Nick','Andy','john','Roger'];
let thePowerStation = duranDuran.slice(2,4);
console.log(duranDuran);
console.log(thePowerStation);
ミワミワ

section03_さまざまな文字列

t4_3.js
console.log("つみトレ4章: SECTION_03");
console.log("さまざまな文字列");
t4_3.js
// c4_3_1.js
let word = 'JavaScript';
console.log(word[0],word[4]);
t4_3.js
// c4_3_2.js
let atsumori = '下天の内を比ぶれば\nゆめ幻のごとくなり';
console.log(atsumori);
t4_3.js
// c4_3_3.js
console.log('\tabc');
console.log('a \tabc');
console.log('ab \tc');
t4_3.js
// c4_3_4.js
console.log('You say \'goodbye \'');
console.log('and I say \'hello \'');
t4_3.js
// c4_3_5.js
let mailText = `親方様

お世話になっております。
服部です。

今週のシフトをお送りします。
月曜 服部
火曜 川村`;
console.log(mailText);
t4_3.js
// c4_3_6.js
let animal = '鶴';
let longevity = 1000
console.log(`${animal}${longevity}`);
t4_3.js
// c4_3_7.js
console.log(String.raw`\Users\libroworks\Documents\note.txt`);
ミワミワ

section_4 文字列を操作する

t4_4.js
console.log("つみトレ4章: SECTION_04");
console.log("文字列を操作する");

// c4_4_1.js
let text = 'ninja';
console.log(text.includes('j'));
t4_4.js
// c4_4_2.js
let url = 'https://libroworks.co.jp';
console.log(url.startsWith('https://'));
console.log(url.endsWith('.com'));
t4_4.js

// c4_4_3.js
let message = '忍者です。伊賀市出身です。';
console.log(message.repeat('です','でござる'));
console.log(message.replaceAll('です','でござる'));
t4_4.js
// c4_4_4.js
let toName =' 服部 様\n';
console.log(toName.trim());
t4_4.js
// c4_4_5.js
let poetry = '忍ぶれど 色に出にけり 我が恋は';
console.log(poetry.split(''));
t4_4.js
// c4_4_6.js
console.log('臨'.concat('兵','闘','者','皆','陣'));
ミワミワ

section_5 オブジェクトリテラルでデータをまとめる

t4_5.js
console.log("つみトレ4章: SECTION_05");
console.log("オブジェクトリテラルでデータをまとめる");

let scores = {
    math: 98,
    japanese: 70,
    science: 89,
};

console.log(scores);
console.log(scores['math'],scores.japanese);

let subject = 'science';
console.log(scores[subject]);

scores.science = '欠席';
scores['english'] = 'A+';
console.log(scores);

console.log('music in scores');