Array of objects 次のarray of objectsを例にします const tweets = [ { id: 10512, message: "Hello Twitter 👋", stats: { likes: 41, retweets: 54 } }, { id: 41241, message: "How do you keep track of your n […]
NovelAIを使ったイラスト作成の例を紹介します。 ペロペロキャンディの服 プロンプト ((ultra-detailed)),masterpiece,best quality,(1 girl),(illustration),((((full-length figure)))), paint right up to the tip of the head,((transparent backgro […]
Array of objectsの例 const tweets = [ { id: 10512, message: "Hello Twitter 👋", stats: { likes: 41, retweets: 54 } }, { id: 41241, message: "How do you keep track of your notes?", stats: { likes: […]
const tweets = [ { id: 1080777336298049537, message: "Hello Twitter 👋", created_at: "2020-01-03 11:46:00" }, { id: 1080777336298195435, message: "How do you keep track of your notes?", created […]
Nullish coalescing と optional chaining の合わせ技を見ていきましょう。 let name = undefined; if (user.details && user.details.name && user.details.name.firstName) { name = user.details.name.firstName; […]
JavaScriptでnullとundefinedの違いとは何でしょうか nullとはpropertyがまだ定義されていないこと undefinedとはpropertyが存在するけれども値がemptyであること です。 例を見てみましょう。 const user = { id: 35, name: SakuraMiko, age: null } console.log(user.age) // n […]
Nulish coalescing (ヌリッシュ コアレッシング) とは新しくJavaScriptに導入されたoperatorで、 ?? です。 ?? の左側が null または undefined の場合は、右側に書かれたものをデフォルト値として使います。 ちなみに、null と undefined をまとめてnullish valueといいます。 何言ってるかよくわからないと思うので、早速例で […]
Optional chaining とは オブジェクトに特定のプロパティが存在するかどうかあやしいときには、Optional chainingというものが使えます。 たとえば、 const user = { details: { name: { firstName: "Sam" } }, data: null } というオブジェクトがあったとします。 しかし、あなたはuserというオブジェクトの中 […]
Objectのkeyを抽出するには、Object.keys()を使います const settings = { theme: "Dark", version: "2.4.1", beta: false }; const keys = Object.keys(settings); console.log(keys); // ["theme", "version", "beta"] Object.ke […]
Array destructuring const dimensions = [20, 5] // create variables const [width, height] = dimensions; // log them console.log(width); //20 console.log(height); //5 [20, 5]という配列から、widthに20、heightに5が格納 […]