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 7917387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:07:38+00:00 2026-06-03T15:07:38+00:00

I have an element in my array that when I print out the value

  • 0

I have an element in my array that when I print out the value of that specific element I get an empty value.

puts my_listing[2].inspect
[]

When I check to see if that specific element is empty, using empty? it returns true:

puts my_listing[2].empty?
true

But when I cycle through the entire array, checking to see if i is empty, it doesn’t find that particular element.

my_listing.each do |i|
    if i.empty?
        puts i
    end
end

i (in this case 2) is never printed to the screen.

Why is that?

Basically, I am trying to get rid of all the elements in the array that are empty (in this case the element at index 2) but I am not sure how to even get at those elements.

What am I missing?

Thanks.

  • 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-03T15:07:39+00:00Added an answer on June 3, 2026 at 3:07 pm

    Oh please iterate like this

           my_listing.each_with_index do |i,index|
              if i.blank?
                 puts index.inspect
              end
           end
    

    It give you index of array which will be empty or nil.

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

Sidebar

Related Questions

Suppose I have an array that mimics a database table. Each array element represents
I have HTML that looks like this: <form id=kinodForm> <input type=text name=element[5] value=krispy kreme
The problem is I have an array that has the key value pairs as
I have a 1D array that got i*50 elements..i is a random number and
Let's say I have a 10 element array: from ctypes import * arr =
how i can duplicate one element from array: for example, i have this array:
I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have an array of structs and I intend to pass each element of
I have a two dimensional JSON array where each element contains several attributes. The
I have to load an array of doubles from a file, multiply each element

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.