Split string based on spaces and read that in angular2

前端 未结 2 1937
有刺的猬
有刺的猬 2021-02-07 09:58

I am creating a pipe in angular2 where I want to split the string on white spaces and later on read it as an array.

let stringToSplit = \"abc def ghi\";
StringTo         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 10:17

    Made a few changes:

    let stringToSplit = "abc def ghi"; let x = stringToSplit.split(" "); console.log(x[0]);

    The split method returns an array. Instead of using its result, you are getting the first element of the original string.

提交回复
热议问题