すべて置換
VaRの例= 「ポテトポテト」。
console.log(example.replace(/ POT /、 "トム")); //置き換えます
console.log(example.replace(/ POT / G、 "トム")); //グローバル交換
ユニークな値の抽出
エントリは、VARを= [ 1、 2、 2、 3、 4、 5、 6、 6、 7、 7、 8、 4、 2、 1]
のvar unique_entries = [新しい新しい... セット(エントリそれを)]; //の作成しますユニークな値を持つ新しい配列
デジタルに変換した文字列
the_string = "123";
console.log(+ the_string); // 123
the_string = "こんにちは";
console.log(+ the_string)。// NAN
ランダム配列の要素を配置
VAR my_listという= [ 1、 2、 3、 4、 5、 6、 7、 8、 9]。
console.log(my_list.sort(関数(){ リターン Math.random() - 0.5 }))。
多次元配列をフラット化
VARエントリ= [ 1、[ 2、 5]、[ 6、 7]、 9]。
VaRのflat_entries = [] .concat(...エントリ)。
条件文を短く
IF(使用可能){
addToCartは();
}で置換することができます
利用可能&& addToCart()
動的なプロパティ名
constのダイナミック= 'フレーバー';
VARアイテム= { 名: 'コーラ'、 [動的]: 'チェリー' } にconsole.log(アイテム)// {名: "コーラ"、味: "チェリー"}
使用長さ調整/空の配列
VARエントリ= [ 1、 2、 3、 4、 5、 6、 7]。
entries.length = 4。
(エントリ)CONSOLE.LOG。// [1、2、3、4]