Search code examples
javascriptarraysstringstring-length

individual string length in array javascript


I need to create a function that takes in four strings and returns an array containing the length of each string. I was given this:

function stringLengths(str1, str2, str3, str4) {
  //
}

I've created an array of strings and I've searched google for so long all words are starting to look the same.


Solution

  • here is your code

    function stringLengths(str1, str2, str3, str4) { 
      return [str1.length, str2.length, str3.length, str4.length]
    }
    
    console.log(stringLengths('1','bb','ccc','dddd'))