Skip to content
Advertisement

Check a list contains given elements

I want to check if my list’s first four elements are digits. what i did is as follows:

JavaScript

But this gives the following error.

JavaScript

How can I achieve this?

Advertisement

Answer

The error is telling you that you can’t do some_list in some_string – after all, a list consists of characters, not lists, so it’s pointless. You want to check if all the characters in your list are in the string, so:

JavaScript

The 0 in 0:4 is not needed, it’s the default.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement