Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  10] [ 7]  / answers: 1 / hits: 5570  / 9 Years ago, mon, march 2, 2015, 12:00:00

Maybe I'm making a very stupid mistake but here it goes. I want to take [ 'hr' ] and turn it into [ '* * *' ] So I did this:



var hr = jsonml[i]

console.log(hr)
// outputs: [ 'hr' ]
hr.replace(/hr/g, '* * *')


But I get this error:




TypeError: Object hr has no method 'replace'




What am I doing wrong?


More From » arrays

 Answers
2

Because hr is Array, try this



hr[0] = hr[0].replace(/hr/g, '* * *');


or



hr = hr[0].replace(/hr/g, '* * *');

[#38883] Sunday, March 1, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryantc

Total Points: 455
Total Questions: 96
Total Answers: 110

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
bryantc questions
Fri, Aug 13, 21, 00:00, 3 Years ago
Tue, Mar 30, 21, 00:00, 3 Years ago
Fri, Jun 5, 20, 00:00, 4 Years ago
Wed, May 27, 20, 00:00, 4 Years ago
;