Ask coding questions

← Back to all posts
Forcing a Function to Contain a Object or a Array Value in a Function Parameter through the UX
Coding1000 (9)

So is it possible for a function to want you to add a array or a object in it's parameter, like if you used a function called yeeboi() but yeeboi has parameter and it's parameter want you to add a array, not just because you have a choice to add a array or other value but forces you to use an array as an object instead of adding a object, string, Boolean, nor a number?

Commentshotnewtop
Coding1000 (9)

WOW! It Work Thank YOU!

maxyang (32)

What language are using?

Highwayman (1367)

I took a little to think about it and best I can come up with is

function nothing(must_be_string) {
  if( (typeof must_be_string) != (typeof "strthang") ) {
    throw new TypeError(`must_be_string must be of the type ${ typeof "jehd" }`);
  }
}

Resources:

Coding1000 (9)

But how do you do that

Highwayman (1367)

You could check the type to make sure it’s an array and then raise and exception if it isn’t.

Coding1000 (9)

And if it is, how do you do it?