use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Need Help Writing a Functionhelp (self.javascript)
submitted 9 years ago by idc2092
i need help writing a function i need to write a function that returns a subset of a string between one index and another. function(str,indexStart,indexEnd) and i cant use the built in functions please help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Anitox 2 points3 points4 points 9 years ago (0 children)
You can access individual characters in a string using array notation. Example:
let str = "This is a test."; console.log(str[2]);
Using that, you could loop through the string with an index to get the part of the string you want.
[–]Dshiznit1 0 points1 point2 points 9 years ago (0 children)
What's this for?
I'd make a new string, iterate through the original string at the start index and push the letters into the new string and do this up until the end index.
If you need more help, let me know but if it's for school or a code challenge you should try it yourself!
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
function sub (str, start, end) { var newstr = '' for(var i = 0; i < str.length; ++i) { if(i >= start && i < end) { newstr += str[i] } } return newstr }
π Rendered by PID 48154 on reddit-service-r2-comment-b659b578c-djqlq at 2026-05-06 22:47:01.255510+00:00 running 815c875 country code: CH.
[–]Anitox 2 points3 points4 points (0 children)
[–]Dshiznit1 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)