Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  65] [ 2]  / answers: 1 / hits: 16041  / 8 Years ago, wed, september 28, 2016, 12:00:00

I have an array var plans=[a, b, c, d ]; with prices based monthly any yearly.



Consider- a and b are monthly and c and d are yearly.



So, I want to split the array based on the monthly and yearly values and store the values in to separate arrays



var monthly_plans=[]; and  var yearly_plans=[]


So, how do I do this?



I have used the js split() function before but on a very basic level.


More From » arrays

 Answers
80

I think it will be a better avenue to use a for.



Example:



for (var i=0;i<plans.length;i++)
{
if(plans[i] == 'monthly condition')
{
monthly_plans.push(plans[i]);
}
else
{
yearly_plans.push(plans[i]);
}
}

[#60565] Monday, September 26, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;