1

Lets say if i have a multiple numbers and one is 54833928. I type into input '5483' and if i click some element i would want to show all these numbers to there. String.prototype.contains -> helped me with words, but how can i accomplish same thing with numbers. So i have like..

<div class="item" data-number="5553498"> some random text </div> <div class="item" data-number="5552134"> some random text </div> <div class="item" data-number="554325"> some random text </div> <div class="item" data-number="5555432"> some random text </div> <input type="text" placeholder="number"><span class="click_find">find</span> js - var something_obj = { "number": "empty" }; if (( number.contains(something_obj.number) || something_obj.number == 'empty') { blabla } 

cant get numbers with using .contains, only something_obj.number == number, but ofcourse it only gives me exact numbers, so i have to put only right number right away and if i put less numbers it returns 0.

0

3 Answers 3

2

Try this:

var num = 54833928; num.toString().includes("5483"); //true 

String.prototype.includes()

Sign up to request clarification or add additional context in comments.

1 Comment

Worked! Thank you! :)
0

Convert that number to String temporarily : And to convert it , just use + operator with empty string

5553498+'' === '5553498' 

Now you can handle it as String and use String#prototype#contains

Comments

0

You can typecast Number to String using:

var str = String(num); 

and apply String.prototype.contains.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.