2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで配列内の文字列から最も文字数の小さい要素を取得する方法。

Last updated at Posted at 2019-12-18

はじめに

短く書くにはどうすればいいか調べたのでまとめたよ。

ゴール

index.js
const string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";

function findShortWord(s){
    return Math.min(...s.split(" ").map (s => s.length));
}

console.log(findShortWord(string));

概要

Math.min()

スプレッド構文(...)

String.prototype.split()

Array.prototype.map()

さいごに

  • スプレッド構文(...)をちゃんと勉強したけど、こんなに便利だと思わなかった。
2
0
0

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?