0
0

More than 3 years have passed since last update.

JavaScriptメモ

Last updated at Posted at 2019-10-21

.test

regexp.test(str)

regexp: 正規表現、str:チェックしたい文字列

与えられた文字列を検索し、その結果はtrue/falseで返す

const required = val => !!val.trim()

以下と同じ意味

const required = function (val) {
   return !!val.trim() //trim()はvalの前後の空白を取り除く
}

Object.keys

オブジェクトのキーだけを配列で取得

const object1 = {
  a: 'somestring',
  b: 42,
  c: false
};

console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]

.find

提供されたテスト関数を満たす配列内の最初の値を返す。

var array1 = [5, 12, 8, 130, 44];

var found = array1.find(function(element) {
  return element > 10;
});

console.log(found);
// expected output: 12
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0