Get first letter of each word in a string, in JavaScript

后端 未结 17 1650
后悔当初
后悔当初 2020-12-05 04:00

How would you go around to collect the first letter of each word in a string, as in to receive an abbreviation?

Input: "Java Script Object

17条回答
  •  死守一世寂寞
    2020-12-05 04:42

    Yet another option using reduce function:

    var value = "Java Script Object Notation";
    
    var result = value.split(' ').reduce(function(previous, current){
        return {v : previous.v + current[0]};
    },{v:""});
    
    
    $("#output").text(result.v);
    
    

提交回复
热议问题