How can I check whether an item already exists in state?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).



const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];

const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];

const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];

const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];


class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);



handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;

switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));











render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)

</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)













share|improve this question
























  • Check out here: regex101.com/r/fFIS01/1

    – Masious
    Nov 14 '18 at 2:23












  • That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

    – Hernan Ariel
    Nov 14 '18 at 2:26











  • Can you provide a jsFiddle?

    – GMaiolo
    Nov 14 '18 at 2:40











  • Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

    – Hernan Ariel
    Nov 14 '18 at 2:53











  • @HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

    – Ramesh
    Nov 14 '18 at 3:35

















2















Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).



const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];

const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];

const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];

const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];


class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);



handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;

switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));











render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)

</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)













share|improve this question
























  • Check out here: regex101.com/r/fFIS01/1

    – Masious
    Nov 14 '18 at 2:23












  • That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

    – Hernan Ariel
    Nov 14 '18 at 2:26











  • Can you provide a jsFiddle?

    – GMaiolo
    Nov 14 '18 at 2:40











  • Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

    – Hernan Ariel
    Nov 14 '18 at 2:53











  • @HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

    – Ramesh
    Nov 14 '18 at 3:35













2












2








2








Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).



const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];

const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];

const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];

const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];


class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);



handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;

switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));











render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)

</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)













share|improve this question
















Is there anyway that I could check if a number already exists (and for instance, if there are more than one instance of a particular number, etc) in state with this code? I can´t figure out any, and I´ve tried all methods I could think of (Indexof, contains, etc, even turning value into an array didn´t help).



const button1 = [number: 'one', value: '1',number: 'two', value: '2',number: 'three', value: '3',number: 'divide', value: '/'];

const button2 = [number: 'four', value: '4',number: 'five', value: '5',number: 'six', value: '6',number: 'add', value: '+'];

const button3 = [number: 'seven', value: '7',number: 'eight', value: '8',number: 'nine', value: '9',number: 'subtract', value: '-'];

const button4 = [number: 'zero', value: '0',number: 'decimal', value: '.',number: 'equals', value: '=',number: 'multiply', value: '*'];


class Calculator extends Component
constructor(props)
super(props);
this.state = value: "0";
this.handleClick = this.handleClick.bind(this);



handleClick(evt)
const id = evt.target.id;
const result = evt.target.value;

switch(id)
case 'clear':
this.setState( value: "0");
break;
case 'equals':
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default: this.setState(prevState => (
value: `$prevState.value$result`.replace(/([/+-/*=])([/+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "")
.replace(/.+/g,".")
));











render()
return(
<div id="container">
<Display value=this.state.value />
<div>
button1.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)

</div>
<div>
button2.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button3.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
button4.map((el, index) => <Button onClick=this.handleClick key=el.index id=el.number value=el.value />)
</div>
<div>
<Button onClick=this.handleClick id="clear" value='clear' />
</div>
</div>
)










javascript reactjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 3:08









isherwood

37.6k1082114




37.6k1082114










asked Nov 14 '18 at 2:16









Hernan ArielHernan Ariel

13817




13817












  • Check out here: regex101.com/r/fFIS01/1

    – Masious
    Nov 14 '18 at 2:23












  • That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

    – Hernan Ariel
    Nov 14 '18 at 2:26











  • Can you provide a jsFiddle?

    – GMaiolo
    Nov 14 '18 at 2:40











  • Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

    – Hernan Ariel
    Nov 14 '18 at 2:53











  • @HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

    – Ramesh
    Nov 14 '18 at 3:35

















  • Check out here: regex101.com/r/fFIS01/1

    – Masious
    Nov 14 '18 at 2:23












  • That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

    – Hernan Ariel
    Nov 14 '18 at 2:26











  • Can you provide a jsFiddle?

    – GMaiolo
    Nov 14 '18 at 2:40











  • Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

    – Hernan Ariel
    Nov 14 '18 at 2:53











  • @HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

    – Ramesh
    Nov 14 '18 at 3:35
















Check out here: regex101.com/r/fFIS01/1

– Masious
Nov 14 '18 at 2:23






Check out here: regex101.com/r/fFIS01/1

– Masious
Nov 14 '18 at 2:23














That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

– Hernan Ariel
Nov 14 '18 at 2:26





That regex doesn´t seem to match anything. I have a small problem with the decimal input (I need to block out certain contexts: number.number.number for instance or number +.). My previous methods didn´t seem to accomplish this, so I want to see if I could check for the number in state before adding a decimal.

– Hernan Ariel
Nov 14 '18 at 2:26













Can you provide a jsFiddle?

– GMaiolo
Nov 14 '18 at 2:40





Can you provide a jsFiddle?

– GMaiolo
Nov 14 '18 at 2:40













Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

– Hernan Ariel
Nov 14 '18 at 2:53





Yeah. Basically this, but with the buttons mapped from arrays: codesandbox.io/s/z293rk7y2m

– Hernan Ariel
Nov 14 '18 at 2:53













@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

– Ramesh
Nov 14 '18 at 3:35





@HernanAriel - number +. is a valid context right? it should be treated as number + 0.number ?

– Ramesh
Nov 14 '18 at 3:35












2 Answers
2






active

oldest

votes


















1














In Handle click, try replacing the default to below



 handleClick(evt) 
const id = evt.target.id;
let result = evt.target.value;

switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".")
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");

return
value
;
);







share|improve this answer

























  • I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

    – Hernan Ariel
    Nov 14 '18 at 3:43











  • Change the const in result to let

    – Ramesh
    Nov 14 '18 at 3:52











  • It sort of works, but it still allows: .+.+. and things like that

    – Hernan Ariel
    Nov 14 '18 at 3:57











  • Updated code. pls check

    – Ramesh
    Nov 14 '18 at 4:07











  • Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

    – Hernan Ariel
    Nov 14 '18 at 4:14


















0














The method you're looking for is includes



EDIT per your additional information:



var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);




You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.






share|improve this answer

























  • Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

    – Hernan Ariel
    Nov 14 '18 at 3:07












  • Updated for you

    – Jake Roby
    Nov 14 '18 at 3:15











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292245%2fhow-can-i-check-whether-an-item-already-exists-in-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In Handle click, try replacing the default to below



 handleClick(evt) 
const id = evt.target.id;
let result = evt.target.value;

switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".")
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");

return
value
;
);







share|improve this answer

























  • I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

    – Hernan Ariel
    Nov 14 '18 at 3:43











  • Change the const in result to let

    – Ramesh
    Nov 14 '18 at 3:52











  • It sort of works, but it still allows: .+.+. and things like that

    – Hernan Ariel
    Nov 14 '18 at 3:57











  • Updated code. pls check

    – Ramesh
    Nov 14 '18 at 4:07











  • Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

    – Hernan Ariel
    Nov 14 '18 at 4:14















1














In Handle click, try replacing the default to below



 handleClick(evt) 
const id = evt.target.id;
let result = evt.target.value;

switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".")
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");

return
value
;
);







share|improve this answer

























  • I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

    – Hernan Ariel
    Nov 14 '18 at 3:43











  • Change the const in result to let

    – Ramesh
    Nov 14 '18 at 3:52











  • It sort of works, but it still allows: .+.+. and things like that

    – Hernan Ariel
    Nov 14 '18 at 3:57











  • Updated code. pls check

    – Ramesh
    Nov 14 '18 at 4:07











  • Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

    – Hernan Ariel
    Nov 14 '18 at 4:14













1












1








1







In Handle click, try replacing the default to below



 handleClick(evt) 
const id = evt.target.id;
let result = evt.target.value;

switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".")
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");

return
value
;
);







share|improve this answer















In Handle click, try replacing the default to below



 handleClick(evt) 
const id = evt.target.id;
let result = evt.target.value;

switch (id)
case "clear":
this.setState( value: "0" );
break;
case "equals":
this.setState(prevState => (
value: math.eval(this.state.value)
));
break;

default:
this.setState(prevState =>
const numbers = prevState.value.split(/[+-*=]/g);
const lastNumber = numbers[numbers.length - 1];
if (result === ".")
let value = `$prevState.value$result`
.replace(/([+-*=])([+-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=.)/, "0")
.replace(/^0+B/, "");

return
value
;
);








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 4:06

























answered Nov 14 '18 at 3:33









RameshRamesh

10.1k23776




10.1k23776












  • I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

    – Hernan Ariel
    Nov 14 '18 at 3:43











  • Change the const in result to let

    – Ramesh
    Nov 14 '18 at 3:52











  • It sort of works, but it still allows: .+.+. and things like that

    – Hernan Ariel
    Nov 14 '18 at 3:57











  • Updated code. pls check

    – Ramesh
    Nov 14 '18 at 4:07











  • Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

    – Hernan Ariel
    Nov 14 '18 at 4:14

















  • I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

    – Hernan Ariel
    Nov 14 '18 at 3:43











  • Change the const in result to let

    – Ramesh
    Nov 14 '18 at 3:52











  • It sort of works, but it still allows: .+.+. and things like that

    – Hernan Ariel
    Nov 14 '18 at 3:57











  • Updated code. pls check

    – Ramesh
    Nov 14 '18 at 4:07











  • Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

    – Hernan Ariel
    Nov 14 '18 at 4:14
















I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

– Hernan Ariel
Nov 14 '18 at 3:43





I tried it, but whenever I try to trigger one of the wrong contexts (for instance, 0..), I get: Error: "result" is read-only

– Hernan Ariel
Nov 14 '18 at 3:43













Change the const in result to let

– Ramesh
Nov 14 '18 at 3:52





Change the const in result to let

– Ramesh
Nov 14 '18 at 3:52













It sort of works, but it still allows: .+.+. and things like that

– Hernan Ariel
Nov 14 '18 at 3:57





It sort of works, but it still allows: .+.+. and things like that

– Hernan Ariel
Nov 14 '18 at 3:57













Updated code. pls check

– Ramesh
Nov 14 '18 at 4:07





Updated code. pls check

– Ramesh
Nov 14 '18 at 4:07













Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

– Hernan Ariel
Nov 14 '18 at 4:14





Seems to work. What does this line do? ((lastNumber.match(/./g) || ).length > 0)

– Hernan Ariel
Nov 14 '18 at 4:14













0














The method you're looking for is includes



EDIT per your additional information:



var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);




You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.






share|improve this answer

























  • Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

    – Hernan Ariel
    Nov 14 '18 at 3:07












  • Updated for you

    – Jake Roby
    Nov 14 '18 at 3:15















0














The method you're looking for is includes



EDIT per your additional information:



var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);




You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.






share|improve this answer

























  • Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

    – Hernan Ariel
    Nov 14 '18 at 3:07












  • Updated for you

    – Jake Roby
    Nov 14 '18 at 3:15













0












0








0







The method you're looking for is includes



EDIT per your additional information:



var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);




You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.






share|improve this answer















The method you're looking for is includes



EDIT per your additional information:



var positions = ;
for(i = 0; i < this.state.value.length; i++)
if(this.state.value.charAt(i) === result)
positions.push(i);




You'll have to edit to fit your specific needs (I get the impression you're looking for something specific which you haven't overtly stated) but I imagine this gets you past your obstacle.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 3:14

























answered Nov 14 '18 at 3:05









Jake RobyJake Roby

5,36011327




5,36011327












  • Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

    – Hernan Ariel
    Nov 14 '18 at 3:07












  • Updated for you

    – Jake Roby
    Nov 14 '18 at 3:15

















  • Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

    – Hernan Ariel
    Nov 14 '18 at 3:07












  • Updated for you

    – Jake Roby
    Nov 14 '18 at 3:15
















Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

– Hernan Ariel
Nov 14 '18 at 3:07






Thanks for the reply. I tried that, but I could never get the decimal to work properly. I need to know the position as well, not just if it´s present.

– Hernan Ariel
Nov 14 '18 at 3:07














Updated for you

– Jake Roby
Nov 14 '18 at 3:15





Updated for you

– Jake Roby
Nov 14 '18 at 3:15

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53292245%2fhow-can-i-check-whether-an-item-already-exists-in-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế