Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:57:55+00:00 2026-06-11T21:57:55+00:00

i want to remove array element, but giving error while using splice, i m

  • 0

i want to remove array element, but giving error while using splice,

i m using following function
with myAra as global var,
but in console ,it is giving me an error, TypeError: myAra.splice is not a function

var myAra = Array();
function charCounts(e,textAreaId)
{
    myAra = $("#"+textAreaId).val();
    var countNewLines = stringOccurrences(myAra, "\n");


    if(myAra.length>75)
    {
        for (var i = 75; i >myAra.length; i++) 
        {
            myAra.splice(i, 1);

        }

        $("#"+textAreaId).val(myAra);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:57:57+00:00Added an answer on June 11, 2026 at 9:57 pm

    This is a nice example of why globals are EVIL, sure you declared the variable an array (badly): var myAra = Array() (I’ll explain at the end what’s bad about this), but later on:

    myAra = $("#"+textAreaId).val();//returns a string, variable is now a string, not an array
    

    You’ve reassigned a string to the array, so the variable now references a string constant, and cannot be used as an Array (not safely, in a X-browser way at least).

    Array() is bad, why? Well, for starters, you’re calling a constructor, but you’re not using the new keyword. With arrays that’s not a big problem (it’ll return a new instance all the same), but when you start defining your own objects, and constructors, you’ll find yourself up to your neck in globals.
    Also, suppose you wanted an array and initialize the first element to an int: var anArray = new Array(2);, you won’t get an array that looks like this: anArray[0] === 2, you’ll get anArray === [undefined,undefined]. Compare that to var anArray('2') –> [‘2’]. Given the fact that JS is loosely typed, and you’ll often use variables when initializing an array, it’s hard to tell weather or not you’re passing a numeric string or a number to the constructor.
    The best way to initialize arrays is by using the literal notation: [2,3,4], as an added bonus, it requires less typing, too

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to remove items of a Jagged array using indizes. int[] toRemove; (e.g,
I want to remove an element from a PHP array (and shrink the array
I have the following array setup, i,e: var myArray = new Array(); Using this
I have an array MyArray and I want to remove one element at position
hi i have multidimensional array in php i want to remove an index from
I want to remove the whitespace between the arrays, but I've used different codes
I want to remove the braces so {test} becomes test. I tried {test}.gsub(/\{(.*)\}/,$1) while
I want to remove the decimal part of a number in a cell but
i want to remove the link from my header using CSS so that only
how do I remove an element from a Perl array ref? I've got its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.