Returning array in Javascript function after splitting string

AdjunctProfessorFalcon

Very new to Javascript and not understanding why my tutorial isn't accepting my code as an answer...

Challenge is to create a function that returns an array after breaking up string into separate words.

Here's what I have so far:

function cutName(namestr) {
  var newArray = namestr.split(' ');
  return newArray();
}

This seems to work when called, for example returning the following when given this string "hello does this work" as an argument:

[ 'hello', 'does', 'this', 'work' ]

What the heck am I doing wrong here? Shouldn't the above code suffice for an answer?

whoacowboy

You need to remove the parenthesis from return newArray;. When learning JavaScript, you might want to look into tools like JSBin, they give you a lot of helpful feedback and realtime results.

JavaScript

function cutName(namestr) {
  var newArray = namestr.split(' ');
  return newArray;
}

var arr = cutName('hello does this work');
console.log(Array.isArray(arr));
console.log(arr);

console output

true
["hello", "does", "this", "work"]

See the JSBin

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Splitting a String and returning an array of Strings

After converting string array into integer array, the function is returning a null array

Splitting String into an Array from Function

Function which returns a TABLE after splitting a string

Splitting a string and returning the pieces

Undefined after splitting array of strings (JavaScript)

C: Splitting a string into two strings, and returning a 2 - element array

Splitting Javascript-String with keywords out of an array

Splitting a string multiple ways into an array with Javascript

Javascript returning array from the function

Javascript function returning array empty

Function returning undefined after calling in string

Returning length of array after push in app function

ArrayIndexOutOfBoundsException after splitting a string

Can't change String Array in Swift 2 after returning it from function

Break Out of Function After Returning Promise - JavaScript

Javascript function: Returning value after a split

Calling string from array using loop after onclick function [javascript]

Powershell function returning an array instead of string

Why is the PHP function "implode" returning the string "array"?

returning array of string from function not working as expected

Returning String array in a function with void return type

Storing a string array in a class member function and returning it

Splitting a string into an array then splitting the array again

Java, splitting string into array

String Splitting an Array

splitting Strings into a String Array

Splitting a string of numbers into an array

Why is my recursive JavaScript function not returning the string?