JavaScriptオブジェクトの特定の値のみを乗算しますか?
以下が私たちのオブジェクトだとしましょう-
var employee =
[
{ name: "John", amount: 800 },
{ name: "David", amount: 500 },
{ name: "Bob", amount: 450 }
] 「金額」の値に2を掛ける必要があるのは、金額が500より大きい場合、つまり期待される出力が-
である場合のみです。[
{ name: 'John', amount: 1600 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 900 }
] 例
オブジェクト値を乗算するためのサンプル例を次に示します-
var employee =
[
{ name: "John", amount: 800 },
{ name: "David", amount: 500 },
{ name: "Bob", amount: 450 }
]
console.log("Before multiplying the result=")
console.log(employee)
for (var index = 0; index < employee.length; index++) {
if (employee[index].amount > 500) {
employee[index].amount = employee[index].amount * 2;
}
}
console.log("After multiplying the result=")
console.log(employee) 上記のプログラムを実行するには、次のコマンドを使用する必要があります-
node fileName.js.
ここで、私のファイル名はdemo257.jsです。
出力
これにより、コンソールに次の出力が生成されます-
PS C:\Users\Amit\javascript-code> node demo257.js
Before multiplying the result=
[
{ name: 'John', amount: 800 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 450 }
]
After multiplying the result=
[
{ name: 'John', amount: 1600 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 900 }
] -
JavaScriptのBlobオブジェクト
blobオブジェクトは、不変のblobオブジェクトを表すために使用され、生データを表すために使用されます。 BLOBには、ファイルと同じようにサイズとmimeタイプのプロパティがあります。ファイルはblobの派生物であり、blobはファイルが使用される場所で使用できます。 以下は、JavaScriptでblobオブジェクトを表示するコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name=
-
JavaScriptのRegExpオブジェクト。
RegExpオブジェクトは、テキストの一部を検索および抽出することにより、一部のテキストのパターンマッチングに使用されます。 RegExpオブジェクトは、regexpコンストラクターまたはリテラル構文のいずれかを使用して作成できます。 以下は、JavaScriptのRegExpオブジェクトのコードです- 例 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport"