Activity Forums Salesforce® Discussions How to delete an index from Salesforce JSON Obj?

  • Anurag

    Member
    October 4, 2018 at 2:31 pm

    Hi Chanchal,

    You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.

    import org.json.JSONArray;

    public class RemoveFromJsonArray {
       public static void main(String args[]) throws Exception {
          String [] myArray = {"JavaFX", "HBase", "JOGL", "WebGL"};
          JSONArray jsArray = new JSONArray();
          for (int i=0; i < myArray.length; i++) {
             jsArray.put(myArray[i]);
         }
         System.out.println(jsArray);
         jsArray.remove(3);
         System.out.println("After deleting ::"+jsArray);
       }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos

Pros & Cons of Lightning Component vs. 3rd party frameworks in Salesforce UI development

Video in

Nikita drops by to share his invaluable experience of using popular 3rd party frameworks in Salesforce. http://media.blubrry.com/salesforceway/audio.xmcdn.com/group42/M05/25/57/wKgJ81rXk6XjaZIAAU_I_KtprFM998.m4a